第二首歌开始时MPMusicPlayerController.nowPlayingItem不录制

时间:2015-08-11 18:51:44

标签: ios swift

我已经成功获得有关当前播放歌曲的信息,但是当歌曲改变时,第二首歌曲的信息不会被录制。如何让程序录制多首歌曲?

let nowPlaying = MPMusicPlayerController.systemMusicPlayer().nowPlayingItem
let playing = MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo
let Title = nowPlaying.valueForProperty(MPMediaItemPropertyTitle) as! String
let Artist = nowPlaying.valueForProperty(MPMediaItemPropertyArtist) as! String
let Album = nowPlaying.valueForProperty(MPMediaItemPropertyAlbumTitle) as! String
let duration = nowPlaying.valueForProperty(MPMediaItemPropertyPlaybackDuration) as! NSNumber
let change = nowPlaying.valueForProperty(MPMusicPlayerControllerNowPlayingItemDidChangeNotification) as! String

class ViewController: UIViewController {

var ID3 = UILabel()

    override func viewDidLoad() {
    super.viewDidLoad()

    var ID3 = UILabel(frame: CGRectMake(0,0,400,400))
    ID3.center = CGPointMake(160, 284)
    ID3.textAlignment = NSTextAlignment.Center
    ID3.text = (("Song: " + Title) + "\n" + ("Artist: " + Artist) + "\n" + ("Album: " + Album))
    ID3.numberOfLines = 3
    self.view.addSubview(ID3)


    //prints into the console what song is currently playing
    println("Song: " + Title)
    println("Artist: " + Artist)
    println("Album: " + Album)
    println(change)

0 个答案:

没有答案