MpMoviePlayerController streaming video problem in simulator - objective-c

I am working on MPMoviePlayerController, I am playing a video which is in URL #"http://www... xyz... ITs not playing in simulator.
I am
NSString *url = #"hhttp://www... xyz... ";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];

NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"video.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);
[moviePlayer play];

Related

iOS 7 Video not playing MPMoviePlayerController

This code is working perfect in iOS 8 . but unable to play video in iOS7.The player shows up but plays nothing.Thanks
NSString *url = #"http://.../playlist.m3u8";
NSURL *streamURL = [NSURL URLWithString:url];
self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle= MPMovieControlStyleFullscreen;
self.streamPlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.streamPlayer.shouldAutoplay = YES;
[self.view addSubview:self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
[self.streamPlayer play];
From the documentation:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
Try to set the frame of your video player.

Video is not playing in ios8 using AVPlayer

Video stored in documents directory is not playing if i run app in ios8 but works perfect if i run in ios7
I am downloading video in documents directory using AFNetworking.Here is the code.
NSURLRequest *request = [NSURLRequest requestWithURL:urlVideo];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *path = [dataPath stringByAppendingPathComponent:[urlVideo lastPathComponent]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.isDownloadingComplete = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Video Downloading Failed");
}];
[operation start];
And i am playing that downloaded video using AVPlayer. Here is the code.
NSURL* playbackURL = [[NSURL alloc] initFileURLWithPath:strPath isDirectory:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:[_pl currentItem]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[_pl currentItem]];
AVAsset *asset = [AVURLAsset URLAssetWithURL:playbackURL options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
_pl = [AVPlayer playerWithPlayerItem:anItem];
_pl.volume = 1.0;
_pl.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_pl];
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
layer.frame = CGRectMake(0, 0, 305, 306);
[self.contentView.layer addSublayer: layer];
[_pl play];
I think issue is with Documents Directory as i run the app, the document path is changing every time, but i am sending correct path every time. Here is reference: http://pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/
I finally solved it by following code
I just replaced
[self.contentView.layer addSublayer: layer];
with
[self.layer addSublayer:layer];
And it is working fine, but still i am not getting what is the problem with [self.contentView.layer addSublayer: layer];
Let me know if anyone have strong proof.
Thanks

playing video in ios 6

I wanted to play a video in ios 6. I am using Xcode 4.5. I write code below but getting error
Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay for pause
Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay
Test Demo[736:14003] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
and my code
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"TestVideo" ofType:#"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
// ...
[player play];`
There could be many issues for your error.
1) Set a property for your MPMoviePlayerController and synthesize it. This may occur, if your MPMoviePlayerController releases before it plays.
2) add this code player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
3) As per documentation, .m4v extension is not mentioned to play.
4) Below screenshot will help you about supported formats.
NSString *url = [[NSBundle mainBundle] pathForResource:#"santaMessage" ofType:#"mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
[moviePlayer play];
///this worked like a charm

MPMoviePlayerController: sound but no picture in fullscreen mode

I'm using the following code to play a movie on an iPad 1 running iOS6:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myMovie.mov" ofType:#""]];
self.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:self.moviePlayer];
// Use the new 3.2 style API
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.moviePlayer prepareToPlay];
self.moviePlayer.view.frame = CGRectMake(0, 0, 1024, 768);
[self.uiView addSubview:self.moviePlayer.view];
//[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
This works.
If however I uncomment the line for setFullscreen, I get the movie audio but with a completely black screen, no picture.
I've tried changing the order of a few lines, in particular the play call and the setFullscreen call, with no effect.
Update
This question appears to be directly relevant:
MPMoviePlayerController in full screen issue (showing blank black screen)
first of all change this line : [[NSBundle mainBundle] pathForResource:#"myMovie.mov" ofType:#""] to: [[NSBundle mainBundle] pathForResource:#"myMovie" ofType:#"mov"] and try again
Use this as its working for me:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myMovie" ofType:#"mov"]];
MPMoviePlayerViewController *movieView = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
movieView.moviePlayer.scalingMode = MPMovieScalingModeFill;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[movieView.moviePlayer.view setFrame:CGRectMake(0,0,480,320)];
else
[movieView.moviePlayer.view setFrame:CGRectMake(0,0,1024,768)];
movieView.moviePlayer.view.userInteractionEnabled = FALSE;
movieView.moviePlayer.controlStyle=0;
[movieView setFullscreen:YES];
self.view=movieView.view;

MPMoviePlayerController does not work in ios 5

i have a problem while working with MPMoviePlayerController. It doesnot work in ios 5 just a black screen to show. Not even throws any exception or any error.
Here is my code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"cavity" ofType:#"mov"];
NSLog(#"%#",path);
_movieController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
[_movieController prepareToPlay];
[_movieController setFullscreen:NO];
[_movieController.view setFrame:CGRectMake(10, 25, 287, 213)];
[_movieController setControlStyle:MPMovieControlStyleEmbedded];
[_movieView addSubview:_movieController.view];
[_movieController play];
The _movieController object has been declared in .h file but still not in working condition.
try this
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
[self presentMoviePlayerViewControllerAnimated:mp];