Iam playing m3u8 url(i.e from Wowza Streaming Engine) through mpmovieplayercontroller in ipad. But initially I can observe some delay in playing video. Please help me how can I reduce this delay time in playing the video.
Here is my code:
urlStr=#"http://192.168.1.14:1935/live/teststream/playlist.m3u8";
NSURL *url = [NSURL URLWithString:urlStr];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[videoPlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(doneButtonClicked:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;
[videoPlayer setShouldAutoplay:YES];
videoPlayer.controlStyle=MPMovieScalingModeAspectFit;
//[videoPlayer prepareToPlay];
[_session.previewView addSubview:videoPlayer.view];
[_session.previewView bringSubviewToFront:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0,768, 512);
[videoPlayer play];
Please help me to resolve this issue.
Related
My movie player is playing but does not play any video. It plays only the sound.
My code is given below:
self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:nil];
self.moviePlayer.view.frame=CGRectMake(10, (self.view.frame.size.height-200-64)/2, 300, 200);
[self.moviePlayer setControlStyle:MPMovieControlStyleDefault];
[self.moviePlayer setShouldAutoplay:YES];
self.moviePlayer.allowsAirPlay = YES;
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[self.moviePlayer setContentURL:[NSURL URLWithString:AttachmentUrl]];
[self.view addSubview:self.moviePlayer.view];
self.moviePlayer.fullscreen=YES;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieloadStateHandler:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
Please suggest me what I will need to do.
My experience is that it is better to use: MPMoviePlayerViewController
For example:
MPMoviePlayerViewController *mvPlayerController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL URLWithString:AttachmentUrl]];
I have used AVPlayer for streaming audio. But it makes the app freeze after some seconds.
AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:[songsarray objectAtIndex:songnumber]]];
self.songPlayer = player;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[songPlayer currentItem]];
[self.songPlayer addObserver:self forKeyPath:#"status" options:NSKeyValueObservingOptionNew context:nil];
[self.songPlayer play];
I am npt getting proper way for streaming audio. If anyone has some idea please help me out.
Thanks to all.
NSURL *url = [NSURL URLWithString:#"http://yyyyy.com/radio.m3u"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
NSLog(#"start");
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
NSLog(#"IF");
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
} else {
// Use the old 2.0 style API
// moviePlayer.movie = MPMovieControlModeHidden;
NSLog(#"else");
[moviePlayer play];
}
In the above code is used in ios development,but m3u to play only 20 seconds how to play full m3u in unstoppable please give some tutorials.
I am using this code with the MediaPlayer framework to play a video:
-(void)GrommeVideoExcerpt1
{
NSURL *url1 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"GrommeVideoExcerpt1" ofType:#"mp4"]];
grommePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:url1];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:grommePlayer1];
grommePlayer1.controlStyle = MPMovieControlStyleDefault;
grommePlayer1.shouldAutoplay = YES;
[self.view addSubview:grommePlayer1.view];
[grommePlayer1 setFullscreen:YES animated:YES];
}
But when I play one video, then navigate to another video and try to play it, the app crashes. It gives me this error:
http://pastebin.com/nUGLXEAi
The problem here is you are adding a notification for when the video finishes playing, and that notification triggers a method you do not have (moviePlayBackDidFinish:) causing the crash.
You could implement this method or remove the notification, depends what you want to do after the video is done playing i.e. remove a viewController that plays the video, etc.
//Register notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
//Then the method ...
-(void) moviePlaybackDidFinish:(NSNotification *)aNotification{
[grommePlayer1.view removeFromSuperview];
grommePlayer1 = nil;
}
I am programming an iPad app. In this app I want to open a movie URL in default Quicktime player. When I tried to open the URL in the browser the movie starts playing in the browser. How can I open the movie in the default player (so i can get play pause controls..)
Any help would be much appreciated.
Thanks
Saurabh
Finally I think it is not possible to open the quicktime player on iPad. So I searched on google and found MPMoviePlayerViewController class, which solves my problem quite well.
- (void)viewDidLoad {
NSString *url = [[NSBundle mainBundle]
pathForResource:#"Stock_Footage_Demobroadband"
ofType:#"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[self.view addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
[super viewDidLoad]; }
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[self.view removeFromSuperView];
[player autorelease]; }
I have posted a complete tutorial my blog http://www.makebetterthings.com/blogs/iphone/play-video-on-iphone-and-ipad/