mPlayer- Play Track (by Title)

Discussion in 'iOS Programming' started by xArtx, Dec 19, 2012.

  1. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi Guys,
    I got this simple media player working:

    Code:
            // instantiate a music player
            MPMusicPlayerController *myPlayer =
            [MPMusicPlayerController applicationMusicPlayer];
            
            // assign a playback queue containing all media items on the device
            [myPlayer setQueueWithQuery: [MPMediaQuery songsQuery]];
            
            // start playing from the beginning of the queue
            [myPlayer play];
            
    
    It starts playing your iTunes library.

    Is there a simple way to make it start playing a particular track by it's title,
    if it happens to known that it will be present on the device?
    Cheers, Art.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    I'm not sure what that means.
    I know you can use it to address groups of songs,
    but don't know how it achieves my objective.
    I already know the song title is in the ipod library.

    ----------

    I'm trying to whip up something of a quick karaoke machine
    where the music and lyrics are in foreign languages to help
    me learn German particularly.

    I know I could just include an mp3 copy in the main bundle,
    but that wouldn't be very sleek.
     
  4. robbieduncan, Dec 20, 2012
    Last edited by a moderator: Dec 28, 2012

    robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Did you read the documentation? Reading and understanding documentation is a core programming skill. The MPMediaQuery documentation has a couple of methods that instantly look useful:

    songsQuery and then addFilterPredicate:

    If you are expecting someone to write your code for you then sorry, I think that's pointless as you learn nothing.
     
  5. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #5
    Well I'm getting there :)

    So I decided to write an app that shows album art and track titles,
    and provide basic control of a playlist so I could use it in the car
    when that "Accessory Connected" screen normally appears.

    My app works until I plug it into the car stereo,
    then it appears control over the iPod library,
    and access to album art is no longer possible.


    Is there a way around this?
     
  6. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #6
    Did this:
    http://www.youtube.com/watch?v=ZE7fo83s1V8

    But still can't play a track by title :D

    I'm not sure if the video makes it clear, but if you don't get it,
    try pressing either of the skip buttons in the music player
    ten times as fast as you can... it will only skip about five tracks.
     
  7. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #7
    Look at the MPMediaPropertyPredicate Class Reference which is used in the MPMediaQuery

    http://developer.apple.com/library/...Reference.html#//apple_ref/doc/uid/TP40008219

    ----------

    I have never done anything with the media player but it seems like you will have to set up a MPMediaQuery with a predicate upon the song using the addFilterPredicate: method.

    the filterPredicate that you added would be where you set up the track name filter
     
  8. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #8
    Thanks, I am getting somewhere with this now :)
    If you use the sample in the docs to retrieve a list of playlists
    or titles, you should be able to use that data for the filter.
     

Share This Page