Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-24-2009, 06:39 AM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Location: UK
Posts: 28
comtek is on a distinguished road
Cool MPMediaItemCollection get current play list from iPod?

I'm trying to get current play queue from MPMusicPlayerController.
I came up with a very bad solution, where I pause the music, Skip to next item, until end of list. (with volume=0)

I thought I could do this when the user needs the list (music will be interrupted unfortunately) or in between the first track change.

I have written the following:

Code:
         if (wasPlaying) [m.player.musicPlayer pause];
          
          //Remeber play time
          MPMediaItem *nowPlayingItem     = m.player.musicPlayer.nowPlayingItem;
          NSTimeInterval currentPlaybackTime     = m.player.musicPlayer.currentPlaybackTime;
          
          //So skip through record finding the list
          int c=0;
          NSMutableArray *mediaItemsInList=[[NSMutableArray alloc] initWithCapacity:10]; //[[NSMutableArray alloc] init];
          
          while ((nowPlayingItem!=nil) && (c<15)) // (m.player.musicPlayer.playbackState!=MPMusicPlaybackStateStopped)
          {
               nowPlayingItem = [m.player.musicPlayer nowPlayingItem];
               if  (nowPlayingItem!=nil) [mediaItemsInList addObject:nowPlayingItem];
               
               [m.player.musicPlayer skipToNextItem];
               c++;
               
               NSLog([NSString stringWithFormat:@"%d:%@ %@",c,[nowPlayingItem valueForProperty: MPMediaItemPropertyTitle],
                       [nowPlayingItem valueForProperty: MPMediaItemPropertyArtist]]);
          }

          NSArray *ar=mediaItemsInList;
          MPMediaItemCollection     *mediaItemCollection=[[ MPMediaItemCollection alloc] collectionWithItems:ar];

          //Set media list
          [m.player setUserMediaItemCollection:mediaItemCollection];
          [m.player.musicPlayer setQueueWithItemCollection: mediaItemCollection];
          [mediaItemCollection release];
          [mediaItemsInList release];
Oh yes... I also found after skipping 15 songs it kept repeating the track information, so for some reason the skipToNextItem is not moving forward. But I gues the first 15 tracks are better than NONE

The code gives a SIGABRT error at:

Code:
MPMediaItemCollection     *mediaItemCollection=[[ MPMediaItemCollection alloc] collectionWithItems:ar];
If anyone has any better iteas I would like to know? Or has a solution for the above... If I fix it I will post the code
comtek is offline   Reply With Quote
Old 08-04-2009, 02:41 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: California
Posts: 200
zulfishah is on a distinguished road
Default

Good question. I'm facing the same problem. Anyone done this before?
zulfishah is offline   Reply With Quote
Old 12-27-2009, 09:16 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 57
kdp8791 is on a distinguished road
Default HELP!

Have you guys been able to resolve this issue? I am facing the same problem with my MPMediaItemCollection and am not sure what to do. Please help, and thank you in advance.
kdp8791 is offline   Reply With Quote
Old 04-22-2011, 11:04 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 2
Whiteninga is on a distinguished road
Default

I know this is a pretty old thread, but I don't believe this issue has been resolved. Apple (for some unknown reason) doesn't allow access to the current MPMediaItemCollection that is playing.

The initial code works with a few adjustments:

Code:
NSArray *ar=mediaItemsInList;
MPMediaItemCollection     *mediaItemCollection=[[ MPMediaItemCollection alloc] collectionWithItems:ar];
should be changed to

Code:
MPMediaItemCollection     *mediaItemCollection=[MPMediaItemCollection collectionWithItems:mediaItemsInList];
mediaItemsInList is already an NSArray and doesn't need to be cast. Also, calling alloc on the MediaItemCollection is unnecessary and will cause a crash. If you want to keep the collection around for later just throw a retain on it.

Quote:
Oh yes... I also found after skipping 15 songs it kept repeating the track information, so for some reason the skipToNextItem is not moving forward.
I have found that skipToNextItem isn't always instantly cooperative. I fixed this by testing the previous item to the current nowPlayingItem to see if they are equal. If they are in fact equal, just sleep for a small period of time and try again. This could of course go on indefinitely if 2 songs are the same right after one another, so make sure to set a timeout.
Whiteninga is offline   Reply With Quote
Old 04-22-2011, 11:08 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 2
Whiteninga is on a distinguished road
Default

Oh I forgot to mention that this process can take a looooooong time depending upon how many songs you want to parse through.

I use NSOperation to run it concurrently with whatever I am doing so that the app is still responsive while grabbing the songs.
Whiteninga is offline   Reply With Quote
Old 07-26-2011, 02:05 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
informatics is on a distinguished road
Default

Quote:
Originally Posted by Whiteninga View Post
Oh I forgot to mention that this process can take a looooooong time depending upon how many songs you want to parse through.

I use NSOperation to run it concurrently with whatever I am doing so that the app is still responsive while grabbing the songs.
many thx!
informatics is offline   Reply With Quote
Reply

Bookmarks

Tags
ipod, mpmediaitemcollection, mpmusicplayercontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 320
11 members and 309 guests
chiataytuday, coolman, givensur, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,882
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:19 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0