How to Play Video Stream with Mpmovieplayercontroller in iOS

How to play video stream with MPMoviePlayerController in iOS

Instead of creating a MPMoviePlayerController and adding that to your view, it is probably simpler to create a MPMoviePlayerViewController and present that view controller modally (since you are trying to show your video full screen anyway). Then the MPMoviePlayerViewController can manage the presentation of your video for you.

MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];

mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];

In your moviePlayBackDidFinish delegate method you can then dismiss the model view controller.

How to play youtube video using MPMoviePlayerController?

You cannot play a YouTube vidoe URL in MPMoviePlayerController. For this you have to use

youtube-iso-player-helper - But you cannot play private video URL in youtube-iso-player-helper

XCDYoutubeKit - It is against YouTube Terms and Service.

Play YouTube videos with MPMoviePlayerController instead of UIWebView

The only way to have a youtube video play inside your own app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. This is the technique described at the link that Muxecoid provided (how to play youtube videos within an application), and this is (as far as I know of) the only way to have a youtube video play within an application. You can still have the Youtube application launch by passing the youtube URL to -[UIApplication openURL:], but of course this closes your own application which is often undesirable.

Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.

Playing a stream of bytes on the iPhone MPMoviePlayerController

You could try implementing a custom URL protocol (see NSURLProtocol). Basically you create the protocol and register it, then any in-app requests to load a url having this protocol will be routed to your protocol instance. You'd likely have to mimic the responses that a HTTP server would send for a progressive-download of the file.

This wont work if MPMoviePlayerController uses lower-level CFNetwork calls vs. NSURLConnection to make its requests. This question implies that MPMoviePlayerController DOES make use of NSURLConnectino: How to play movie with a URL using a custom NSURLProtocol?

Also read the URL Loading System docs.

Streaming video over HTTP in IOS

by the way here's how i use mpmovieplayercontroller for streaming :

NSURL *url = [NSURL URLWithString:videoUrl];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame;
if(self.interfaceOrientation ==UIInterfaceOrientationPortrait)
frame = CGRectMake(20, 69, 280, 170);
else if(self.interfaceOrientation ==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation ==UIInterfaceOrientationLandscapeRight)
frame = CGRectMake(20, 61, 210, 170);
[moviePlayer.view setFrame:frame]; // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

[moviePlayer prepareToPlay];
[moviePlayer play];

and then here's the delegate method :

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];

if ([player respondsToSelector:@selector(setFullscreen:animated:)]){
//self.navigationController.navigationBarHidden = YES;
[player.view removeFromSuperview];
}
}

hope this will help you..

MPMoviePlayerController streaming video not play Audio on iPad

First add AVFoundation.framework and add below code.

in .h file

 #import <AVFoundation/AVFoundation.h>

and .m file

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

Is there a way MPMovieplayerViewController can detect if video is a stream?

Use an HTTP HEAD request. If the Content-Type is application/vnd.apple.mpegurl, then it's an http live streaming stream.



Related Topics



Leave a reply



Submit