|
|
|
@ -46,6 +46,35 @@ class AudioManager {
|
|
|
|
|
setupRemoteTransportControls()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentTrack.subscribe { audioTrack in
|
|
|
|
|
guard let audioTrack = audioTrack.element,
|
|
|
|
|
let track = audioTrack else { return }
|
|
|
|
|
do {
|
|
|
|
|
let trackData = try JSONEncoder().encode(track)
|
|
|
|
|
|
|
|
|
|
PINCache.shared.setObject(trackData, forKey: "CurrentTrack")
|
|
|
|
|
} catch {
|
|
|
|
|
print("Encoding failed for Playlist: \(error)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}.disposed(by: disposeBag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playlist.subscribe { audioTracks in
|
|
|
|
|
guard let audioTracks = audioTracks.element else { return }
|
|
|
|
|
|
|
|
|
|
// 缓存当前播放列表
|
|
|
|
|
do {
|
|
|
|
|
let listData = try JSONEncoder().encode(audioTracks)
|
|
|
|
|
|
|
|
|
|
PINCache.shared.setObject(listData, forKey: "CurrentPlaylist")
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
print("Encoding failed for Playlist: \(error)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}.disposed(by: disposeBag)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -77,15 +106,6 @@ class AudioManager {
|
|
|
|
|
func setPlaylist(list: [AudioTrack]) {
|
|
|
|
|
self.playlist.accept(list)
|
|
|
|
|
|
|
|
|
|
// 缓存当前播放列表
|
|
|
|
|
do {
|
|
|
|
|
let listData = try JSONEncoder().encode(list)
|
|
|
|
|
|
|
|
|
|
PINCache.shared.setObject(listData, forKey: "CurrentPlaylist")
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
print("Encoding failed for Playlist: \(error)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -99,17 +119,19 @@ class AudioManager {
|
|
|
|
|
try AVAudioSession.sharedInstance().setMode(.default)
|
|
|
|
|
try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
|
|
|
|
|
|
|
|
|
|
let playerItem: AVPlayerItem = AVPlayerItem.init(asset: CachingAVURLAsset(url: url))
|
|
|
|
|
// let playerItem: AVPlayerItem = AVPlayerItem(url: url)
|
|
|
|
|
// let playerItem: AVPlayerItem = AVPlayerItem.init(asset: CachingAVURLAsset(url: url))
|
|
|
|
|
let playerItem: AVPlayerItem = AVPlayerItem(url: url)
|
|
|
|
|
|
|
|
|
|
print("playerItem \(url)")
|
|
|
|
|
|
|
|
|
|
self.disposeBag = DisposeBag.init()
|
|
|
|
|
self.currentTrack.accept(track)
|
|
|
|
|
|
|
|
|
|
// self.disposeBag = DisposeBag.init()
|
|
|
|
|
player?.pause()
|
|
|
|
|
player = AVPlayer(playerItem: playerItem)
|
|
|
|
|
|
|
|
|
|
player?.play()
|
|
|
|
|
player?.volume = 1
|
|
|
|
|
self.currentTrack.accept(track)
|
|
|
|
|
NotificationCenter.default.post(name: .notiPlayAudioTrack, object: track)
|
|
|
|
|
if currentTrackIndex + 1 == self.playlist.value.count && playerType.value == .FM {
|
|
|
|
|
needAddNewAudio.accept(())
|
|
|
|
@ -144,14 +166,7 @@ class AudioManager {
|
|
|
|
|
}).disposed(by: disposeBag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 缓存当前歌曲
|
|
|
|
|
do {
|
|
|
|
|
let trackData = try JSONEncoder().encode(track)
|
|
|
|
|
|
|
|
|
|
PINCache.shared.setObject(trackData, forKey: "CurrentTrack")
|
|
|
|
|
} catch {
|
|
|
|
|
print("Encoding failed for Playlist: \(error)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|