Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to access the currently played track while the iPhone is connected to an accessory?
    primarykey
    data
    text
    <p>I am trying to receive information about the currently played track in a iOS app. This works pretty fine while the iPhone is <em>not</em> connected to an accessory. If I connect it to my car (Opel Astra, iPhone jack), the following code stops to work <a href="https://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html" rel="noreferrer">as described in the documentation</a>:</p> <blockquote> <p>If you create an iPod music player and the user plays an item from another library using Home Sharing, the value of this property is <code>nil</code>.</p> </blockquote> <p>Code:</p> <pre><code>// nil while connected to an accessory MPMediaItem *nowPlayingMediaItem = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem]; // Works while not connected to an accessory NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle]; </code></pre> <p>I even tried "hacky" stuff like to access "private" properties (<a href="http://www.pixiapps.com/blog/?p=78" rel="noreferrer">original code</a>):</p> <pre><code>MPMediaQuery *query=nil; MPMediaItemCollection *collection=nil; id internalPlayer=nil; Ivar internalPlayeriVar = object_getInstanceVariable(iPod, "_internal", NULL); internalPlayer = object_getIvar(iPod, internalPlayeriVar); NSLog(@"internalPlayer: %@", internalPlayer); Ivar queryIvar = object_getInstanceVariable(internalPlayer, "_query", NULL); query = object_getIvar(internalPlayer, queryIvar); // nil everytime Ivar collectionIvar = object_getInstanceVariable(internalPlayer, "_itemCollection", NULL); collection = object_getIvar(internalPlayer, collectionIvar); // nil everytime </code></pre> <p>or to call private methods:</p> <pre><code>// Same behaviour like [iPod nowPlayingItem], works // only while no accessory is connected MPMediaItem *nowPlayingMediaItem = [iPod nowPlayingItemAtIndex:[iPod indexOfNowPlayingItem]]; // Works while not connected to an accessory NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle]; </code></pre> <p>Its also <em>no</em> solution to access the new <code>MPNowPlayingInfoCenter</code>, its <code>nil</code> all the time.</p> <pre><code>[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo </code></pre> <p>My car plays my music directly without using a iPhone app <em>and</em> it seems my iPhone knows what the car is currently playing because it displays the title, artist and cover icon on the lock screen (and only there). Also the internal play count gets increased.</p> <p>If I check the playback state, it returns also <code>YES</code> if the car plays music:</p> <pre><code>[[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying </code></pre> <p>So, is there any way (may be through calling private methods) to access the song, the car is currently playing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload