|
@@ -9,6 +9,7 @@
|
|
import UIKit
|
|
import UIKit
|
|
import JXSegmentedView
|
|
import JXSegmentedView
|
|
|
|
|
|
|
|
+/// 选中的音乐
|
|
var publishNewMusicSelectedindexPath : IndexPath? = nil
|
|
var publishNewMusicSelectedindexPath : IndexPath? = nil
|
|
|
|
|
|
class PublishNewMusicListView: BaseView {
|
|
class PublishNewMusicListView: BaseView {
|
|
@@ -16,6 +17,7 @@ class PublishNewMusicListView: BaseView {
|
|
|
|
|
|
var categoryId : Int = 0
|
|
var categoryId : Int = 0
|
|
var index : Int? = nil
|
|
var index : Int? = nil
|
|
|
|
+
|
|
var communityMusicItemModels : Array<CommunityMusicItemModel> = []
|
|
var communityMusicItemModels : Array<CommunityMusicItemModel> = []
|
|
|
|
|
|
override func setupViews() {
|
|
override func setupViews() {
|
|
@@ -86,19 +88,15 @@ extension PublishNewMusicListView : UITableViewDelegate, UITableViewDataSource {
|
|
let cell = PublishNewMusicListViewTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
let cell = PublishNewMusicListViewTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
let communityMusicItemModel = communityMusicItemModels[indexPath.row]
|
|
let communityMusicItemModel = communityMusicItemModels[indexPath.row]
|
|
if publishNewMusicSelectedindexPath == nil {
|
|
if publishNewMusicSelectedindexPath == nil {
|
|
- communityMusicItemModel.isSelected = false
|
|
|
|
cell.isSelected = false
|
|
cell.isSelected = false
|
|
}else {
|
|
}else {
|
|
if publishNewMusicSelectedindexPath?.section == index {
|
|
if publishNewMusicSelectedindexPath?.section == index {
|
|
if publishNewMusicSelectedindexPath?.row == indexPath.row {
|
|
if publishNewMusicSelectedindexPath?.row == indexPath.row {
|
|
- communityMusicItemModel.isSelected = true
|
|
|
|
cell.isSelected = true
|
|
cell.isSelected = true
|
|
}else {
|
|
}else {
|
|
- communityMusicItemModel.isSelected = false
|
|
|
|
cell.isSelected = false
|
|
cell.isSelected = false
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
- communityMusicItemModel.isSelected = false
|
|
|
|
cell.isSelected = false
|
|
cell.isSelected = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -108,65 +106,72 @@ extension PublishNewMusicListView : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
let cell = tableView.cellForRow(at: indexPath) as? PublishNewMusicListViewTableViewCell
|
|
let cell = tableView.cellForRow(at: indexPath) as? PublishNewMusicListViewTableViewCell
|
|
-
|
|
|
|
- if publishNewMusicSelectedindexPath?.row != indexPath.row {
|
|
|
|
- publishNewMusicSelectedindexPath = IndexPath(row: indexPath.row, section: index ?? 0)
|
|
|
|
- var mp3url = kApiDownloadPrefix() + "/music/"
|
|
|
|
- mp3url = cell?.communityMusicItemModel?.url?.substring(fromIndex: mp3url.count) ?? ""
|
|
|
|
- cell?.communityMusicItemModel?.musicName = mp3url
|
|
|
|
-
|
|
|
|
- let pathUrl =
|
|
|
|
- PathURLManager.projectFilePath(fileName: mp3url, parentURL: PathURLManager.projectDateFormatPath(dateFormat: "yyyyMM", parentURL:
|
|
|
|
- PathURLManager.projectAudiosPath(parentURL:
|
|
|
|
- PathURLManager.projectResourcesPath(parentURL:
|
|
|
|
- PathURLManager.projectDownloadsPath(parentURL:
|
|
|
|
- PathURLManager.projectDocumentPath())))))!
|
|
|
|
-
|
|
|
|
- if FileManager.default.fileExists(atPath: pathUrl.path) {
|
|
|
|
- cell?.isSelected = true
|
|
|
|
- publishNewMusicSelectedindexPath?.row = indexPath.row
|
|
|
|
- cell?.activityIndicatorView.stopAnimating()
|
|
|
|
- cell?.iconImageView.isHidden = false
|
|
|
|
- //播放
|
|
|
|
- AliPlayerManager.shared.initAudioPlayer(pathUrl: pathUrl.path,startPlayClosure: {
|
|
|
|
- cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- SwiftMoyaNetWorkServiceDownLoad.shared().musicApi(mp3url: mp3url, progressClosure: {
|
|
|
|
- [weak cell] progress in
|
|
|
|
- cell?.activityIndicatorView.startAnimating()
|
|
|
|
- cell?.iconImageView.isHidden = true
|
|
|
|
|
|
+ if publishNewMusicSelectedindexPath?.row != indexPath.row || publishNewMusicSelectedindexPath?.section != index {
|
|
|
|
+ publishNewMusicSelectedindexPath = IndexPath(row: indexPath.row, section: index ?? 0)
|
|
|
|
+ var mp3url = kApiDownloadPrefix() + "/music/"
|
|
|
|
+ mp3url = cell?.communityMusicItemModel?.url?.substring(fromIndex: mp3url.count) ?? ""
|
|
|
|
+ cell?.communityMusicItemModel?.musicName = mp3url
|
|
|
|
+
|
|
|
|
+ let pathUrl =
|
|
|
|
+ PathURLManager.projectFilePath(fileName: mp3url, parentURL:
|
|
|
|
+ PathURLManager.projectDateFormatPath(dateFormat: "yyyyMM", parentURL:
|
|
|
|
+ PathURLManager.projectAudiosPath(parentURL:
|
|
|
|
+ PathURLManager.projectResourcesPath(parentURL:
|
|
|
|
+ PathURLManager.projectDownloadsPath(parentURL:
|
|
|
|
+ PathURLManager.projectDocumentPath())))))!
|
|
|
|
+ if FileManager.default.fileExists(atPath: pathUrl.path) {
|
|
|
|
+ cell?.isSelected = true
|
|
|
|
+ cell?.activityIndicatorView.stopAnimating()
|
|
|
|
+ //播放
|
|
|
|
+ AliPlayerManager.shared.initAudioPlayer(pathUrl: pathUrl.path,startPlayClosure: {
|
|
|
|
+ cell?.iconImageView.isHidden = false
|
|
|
|
+ cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ SwiftMoyaNetWorkServiceDownLoad.shared().musicApi(mp3url: mp3url, progressClosure: { progress in
|
|
|
|
+ cell?.activityIndicatorView.startAnimating()
|
|
|
|
+ cell?.iconImageView.isHidden = true
|
|
|
|
+ cell?.isSelected = false
|
|
|
|
+ }, completion: { [weak cell] (_) -> (Void) in
|
|
|
|
|
|
- }, completion: { [weak cell] (_) -> (Void) in
|
|
|
|
- cell?.isSelected = true
|
|
|
|
- cell?.activityIndicatorView.stopAnimating()
|
|
|
|
- cell?.iconImageView.isHidden = false
|
|
|
|
- publishNewMusicSelectedindexPath?.row = indexPath.row
|
|
|
|
|
|
+ if publishNewMusicSelectedindexPath == indexPath {
|
|
//播放
|
|
//播放
|
|
AliPlayerManager.shared.initAudioPlayer(url: cell?.communityMusicItemModel?.url,startPlayClosure: {
|
|
AliPlayerManager.shared.initAudioPlayer(url: cell?.communityMusicItemModel?.url,startPlayClosure: {
|
|
|
|
+ cell?.activityIndicatorView.stopAnimating()
|
|
|
|
+ cell?.iconImageView.isHidden = false
|
|
|
|
+ cell?.isSelected = true
|
|
cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
})
|
|
})
|
|
-
|
|
|
|
- }) { [weak cell] (loadingStatus) in
|
|
|
|
- cell?.isSelected = false
|
|
|
|
- cell?.activityIndicatorView.stopAnimating()
|
|
|
|
- cell?.iconImageView.isHidden = false
|
|
|
|
- publishNewMusicSelectedindexPath = nil
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- //暂停播放
|
|
|
|
- AliPlayerManager.shared.audioPlayer.pause()
|
|
|
|
- cell?.iconImageView.image = kImage(name: "music_btn_play")
|
|
|
|
- cell?.isSelected = false
|
|
|
|
- publishNewMusicSelectedindexPath = nil
|
|
|
|
- }
|
|
|
|
|
|
+ }else {
|
|
|
|
+ cell?.isSelected = false
|
|
|
|
+ cell?.activityIndicatorView.stopAnimating()
|
|
|
|
+ cell?.iconImageView.isHidden = false
|
|
|
|
+ cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }) { [weak cell] (loadingStatus) in
|
|
|
|
+ cell?.isSelected = false
|
|
|
|
+ cell?.activityIndicatorView.stopAnimating()
|
|
|
|
+ cell?.iconImageView.isHidden = false
|
|
|
|
+ cell?.iconImageView.image = kImage(name: "music_btn_pause")
|
|
|
|
+ publishNewMusicSelectedindexPath = nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ //暂停播放
|
|
|
|
+ AliPlayerManager.shared.audioPlayer.pause()
|
|
|
|
+ cell?.iconImageView.image = kImage(name: "music_btn_play")
|
|
|
|
+ cell?.isSelected = false
|
|
|
|
+ publishNewMusicSelectedindexPath = nil
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
|
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
|
let cell = tableView.cellForRow(at: indexPath) as? PublishNewMusicListViewTableViewCell
|
|
let cell = tableView.cellForRow(at: indexPath) as? PublishNewMusicListViewTableViewCell
|
|
cell?.isSelected = false
|
|
cell?.isSelected = false
|
|
cell?.iconImageView.image = kImage(name: "music_btn_play")
|
|
cell?.iconImageView.image = kImage(name: "music_btn_play")
|
|
|
|
+ cell?.activityIndicatorView.stopAnimating()
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
@@ -197,7 +202,7 @@ extension PublishNewMusicListView : JXSegmentedListContainerViewListDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
func listWillAppear() {
|
|
func listWillAppear() {
|
|
- self.tableView.reloadData()
|
|
|
|
|
|
+ tableView.reloadData()
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|