user1288402
user1288402

Reputation: 35

how to play video from url using mpplayer?

I am new to this iPhone development. I would like to play the video from url which can be youtube videos or from any url. How can i do this ? Can any one suggest me a good method. I have tried

   NSURL *fileURL = [NSURL URLWithString:url];
    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
   [moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)]; 
   [self.view addSubview:moviePlayerController.view];  
   moviePlayerController.fullscreen = YES;  
   [moviePlayerController play]; 

But its not working.

Upvotes: 1

Views: 7148

Answers (3)

Rohit Wankhede
Rohit Wankhede

Reputation: 506

Here try This :

NSString *url = [NSString stringWithFormat:@"http://..........."]; 
NSURL *fileURL = [NSURL URLWithString:url];

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)]; 
[self.view addSubview:moviePlayerController.view];  
moviePlayerController.fullscreen = YES;  
[moviePlayerController play]; 

OR : To get an idea please check out this link. (adding framework and all that stuff)

Upvotes: 0

Squatch
Squatch

Reputation: 1027

I have had this issue since the iOS 5 release, though it was not with YouTube videos. I would get nothing but a blank screen where my video should have been, which sounds like what you are experiencing. This is what I added after the player was added to the view and it solved the problem:

[moviePlayerController setShouldAutoplay:NO];//or yes if you want it to....
[moviePlayerController prepareToPlay];//seems to be a magical fix

Once again, this was an issue I had but IT WAS NOT with YouTube videos, which sounds like it might be part of the problem based on other answers here. You can give it a shot though!

Upvotes: 0

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

You trying to run Video from URL. In this case URL could be simple URL or YouTube,

1.Simple URL:Playing a video (of a supported file format) on the iPhone is very easy using the MPMoviePlayerController class. You just create an instance of the class and initialize it with the URL of the video. The controller plays the video in full screen mode and returns back to your application when it’s done.

2.In case of You Tube: However, if the URL of the video is recognized by the iPhone as a YouTube URL then the Apple URL Scheme mechanism kicks in and launches the YouTube app. In this scenario control will not return to your app after the video has played

So for Playing any type of Url you 'll have create some conditional statementlike as below

if(![str hasPrefix:@"http://www.youtube.com"]){
  //here call your MpMoviePlayerController code which plays the Video.
 //you should need to put method call in which you have Video Playing code.
 }
else {
    //here call the YouTube Video Player Code.
}

Please Go through this link For Playing the YouTube Video.

Good Tutorial at here for playing You tube video in iphone Application.

I hope it'll clears you.

Upvotes: 0

Related Questions