0

I need to play a movie already synchronised from iTunes to Apples 'Movies' App on a iPad, in a view.

I can play a movie from the bundle using MPMoviePlayerController OK. I can get a media Item of all movies (NSArray of MPMediaItem's using MPMediaQuery). However the MPMoviePlayerController only accepts an NSURL - not an MPMediaItem.

So, how can I play a movie when all I have is a MPMediaItem of the movie? Is there another object other than MPMoviePlayerController that does this? Several posts explain how to 'get' a media item but not how to 'set' an item.

Any help is greatly appreciated.

John Goodstadt
  • 678
  • 8
  • 13

2 Answers2

2

each MPMediaItem has an URL which can be accessed with valueForProperty:.

I don't know if you can use that to play it in MPMoviePlayerController though. In theory it should work.

NSURL *url = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];

EDIT: Looks like it's not possible to use that.

MPMediaItemPropertyAssetURL
A URL pointing to the media item, from which an AVAsset object (or other URL-based AV Foundation object) can be created, with any options as desired. Value is an NSURL object.
The URL has the custom scheme of ipod-library. For example, a URL might look like this: ipod-library://item/item.m4a?id=12345
Usage of the URL outside of the AV Foundation framework is not supported.

from: General Media Item Property Keys

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
  • Thanks this has worked! It would have taken a long time to find out '[mediaItem valueForProperty:MPMediaItemPropertyAssetURL]' - Not very intuitive. – John Goodstadt Mar 29 '12 at 14:11
2

Try this

NSURL *url = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:   url];
[player prepareToPlay];
[player.view setFrame: myView.bounds];  // player's frame must match parent's
[myView addSubview: player.view];
[player play];

i think this should work..

MPMediaItem is inherited from MPMediaEntity which has the method valueForProperty:

Ankit
  • 1,684
  • 14
  • 14