Not Showing Movie, Black Screen Appears - ios

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]];

Related

how do i fix MPMoviePlayerViewController

i click on the button here is the code
//NSURL *url = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:self.urlFile];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
_moviePlayer.view.frame = CGRectMake(0, 0, 320, 300);
[_moviePlayer setFullscreen:YES animated:YES];
and it plays but when i press the Done button, here is the method
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
player.initialPlaybackTime = -1;
[player.view removeFromSuperview];
}
it looks like this
sorry dont have enough to post image
it has the black lining on the bottom and the play button disappears as well, how do i load it back to the point it was when the cell was pressed and came to the detailViewController

MP movie controller removes when done button is clicked in iphone

I am playing video in MPmovieController it works fine but player removes when complete video is played.I want that when user pressed done button then video should stop here is the code i am using.
NSURL*myURL=[NSURL fileURLWithPath:url];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:myURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
Try this one:
NSURL *fileURL=[NSURL URLWithString:[[array objectAtIndex:videoid] valueForKey:#"VideoUrl"]];
self.mpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:self.mpPlayer];
[self.mpPlayer.moviePlayer prepareToPlay];
self.mpPlayer.moviePlayer.shouldAutoplay=NO;
[self.mpPlayer.moviePlayer play];
- (void)moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer pause];
[self dismissMoviePlayerViewControllerAnimated];
// [moviePlayer.view removeFromSuperview];
}
may be it will help.
happy coding...
remove this line into your then it will work
[moviePlayerController.view removeFromSuperview];

view doesn't come back after video plays

I'm running the following code. The video plays fine but after it finishes it just goes to a black srcreen, my original view never comes back. When I tap on the black screen i just see the message "loading....." Can someone please explain what I'm doing wrong. Thanks
- (IBAction)video:(UIBarButtonItem *)sender
{
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"IMG_0973" ofType:#"MOV"]];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
//moviePlayer.shouldAutoplay=NO;
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
}
- (void) moviePlayBackDonePressed:(NSNotification*)notification
{
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
}
moviePlayer=nil;
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
}
}
Add this notification Method
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification
object:player];
This method is called after your movie is loaded and in this method you add your moviePlayer view.
-(void)moviePreloadDidFinish:(NSNotification*)notification
{
moviePlayer.controlStyle=MPMovieControlStyleDefault;
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
[moviePlayer setFullscreen:YES animated:YES];
}
In your video IBAction, you need to add the subview before you tell it to play. Switch the lines [moviePlayer play] and [self.view addSubview:moviePlayer.view]. Let us know it it works! Actually you may need to place moviePlayer play even after the full screen line.
i think this will help you .....
-(void)playVideo
{
NSString *contentURL = [[NSBundle mainBundle] pathForResource:#"xyz" ofType:#"mp4"];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:contentURL]];
if (moviePlayerViewController)
{
[moviePlayerViewController.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
[moviePlayerViewController.moviePlayer setFullscreen:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(MovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController.moviePlayer];
[moviePlayerViewController.moviePlayer play];
[navi presentModalViewController:moviePlayerViewController animated:NO];
[moviePlayerViewController release];
moviePlayerViewController = nil;
}
}
-(void)MovieFinished:(NSNotification *)notification
{
MPMoviePlayerController *player = (MPMoviePlayerController *)notification.object;
[player stop];
[[NSNotificationCenter defaultCenter] removeObserver:self];
//do rest of the stuff
}

how to play full m3u audio stream in ios

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.

how iOS play the video by URL

I want to play a video by the URL. I see some sample,the codes like below:
NSString *movieFile= [[NSBundle mainBundle] pathForResource:#"android" ofType:#"mp4"];
videoURL=[[NSURL alloc] initFileURLWithPath:movieFile];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:videoURL];
It play only the local resource.I write some code like:
NSString* strurl =#"https://s3.amazonaws.com/adplayer/colgate.mp4";
videoURL=[NSURL fileURLWithPath:strurl];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:videoURL];
but there is nothing ... why..and how to play video by the url ?
In following code, I am playing a video over the internet from a movie file located on a web server. Dont forget to add MediaPlayer framework and include "MediaPlayer/MediaPlayer.h" in ViewController.h file.
On a button click use following code:
-(IBAction) playVideo:(id)sender
{
NSURL *url=[[NSURL alloc] initWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
Notification method:
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
if ([player respondsToSelector:#selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
Use the following code:
- (IBAction)playBtnPressed {
NSURL *url = [[NSURL alloc] initWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDonePressed:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
//moviePlayer.shouldAutoplay=NO;
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlayBackDonePressed:(NSNotification *)notification {
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
moviePlayer = nil;
}
- (void)moviePlayBackDidFinish:(NSNotification *)notification {
[moviePlayer stop];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
}
Use following line in .h file and add MediaPlayer Framework in your project
import
Try
NSURL *url = [NSURL URLWithString: strurl];

Resources