Is there a way to access the currently played track while the iPhone is connected to an accessory?

后端 未结 4 1472
予麋鹿
予麋鹿 2020-12-29 06:36

I am trying to receive information about the currently played track in a iOS app. This works pretty fine while the iPhone is not connected to an accessory. If I con

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 06:52

    Apple just "fixed that" in iOS 6.1 after I reported it as a bug. The following code now works while my iPhone is connected to my car:

    MPMediaItem *nowPlayingMediaItem = [iPod nowPlayingItem];
    
    NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle];
    
    NSLog(@"Playing title: %@", title);
    

    And, what I really like: It is also possible to change the playing track using the iPod app - the app appears as you expect it, instead of the big white "connected to an accessory" screen. So this may also work programatically.

提交回复
热议问题