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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-09-2010, 03:14 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Sofia, Bulgaria
Posts: 29
cpprulez is on a distinguished road
Default What is the fastest way to get a random MPMediaItem

Hello, gurus
Can you please share some ideas how to get one or more random MPMediaItems from user's iPod Library. Any call to [MPMediaQuery songsQuery].items is waaaaay too slow - for a library of just 800 songs it takes about 19 seconds on my iPod Touch 2G to execute the query. Any thoughts will be greatly appreciated. Thank you
cpprulez is offline   Reply With Quote
Old 06-09-2010, 03:41 PM   #2 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

I have never worked with this so this is a speculation...

... but! couldn't you generate a random number and then retrieve a single song based on that random number?

Just an idea. Sorry if that doesn't make sense or is not possible...

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-10-2010, 02:55 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: Sofia, Bulgaria
Posts: 29
cpprulez is on a distinguished road
Default Thanks :)

Thank you, Robert
I thought of that too, but I'm afraid it won't work, because the persistent id of a song is of type Int64
cpprulez is offline   Reply With Quote
Old 07-13-2010, 12:11 PM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 13
AlanTaylor is on a distinguished road
Default

Quote:
Originally Posted by cpprulez View Post
Thank you, Robert
I thought of that too, but I'm afraid it won't work, because the persistent id of a song is of type Int64
You should build an MPMediaCollection, then count how many there are.
Next, generate a random number and use the count to limit the maximum random number.
Finally, call the item from the collection at that index. It's almost instantaneous.
AlanTaylor is offline   Reply With Quote
Reply

Bookmarks

Tags
ipod library, media, random

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: 362
6 members and 356 guests
.Snipe, AragornSG, baja_yu, guusleijsten, hussain1982, Paul Slocum
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

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