5

How to play the video file from assets library? I have the URL of file like

"assets-library://asset/asset.MOV?id=1000000023&ext=MOV"

But I am unable to play this file in media player using the following code:

NSString *urlAddress = @"assets-library://asset/asset.mov?id=1000000023&ext=mov"; 
NSURL *theURL = [NSURL URLWithString:urlAddress]; 
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
skink
  • 5,133
  • 6
  • 37
  • 58
Naveed Rafi
  • 2,503
  • 5
  • 32
  • 40

1 Answers1

5

I was also getting problem, and got the solution. I used the following code and it worked for me. The urlAddress is the url for the video by ALAssetsLibrary.

-(void)playVideo:(NSString *)urlAddress{

NSString *newUrl = [[NSString alloc] initWithFormat:@"%@",urlAddress];

NSURL *theURL = [NSURL URLWithString:newUrl];

//player = [[MPMoviePlayerController alloc] init];

[player setContentURL:theURL];
[player prepareToPlay];
[player play]; 

}
ManuPK
  • 11,623
  • 10
  • 57
  • 76
  • for those who can't get the video to play, call [player play]; after a short delay as object can take a while to prepare video – Shams Ahmed May 02 '14 at 07:23
  • 1
    NSString *newUrl = [[NSString alloc] initWithFormat:@"%@",urlAddress]; This does nothing. You create a string with the exact same string. I still can't get anything to work in iOS 8 when I have a assets-library based URL for the media player. – Kevin Feb 24 '15 at 21:08