iOS 7 Video not playing MPMoviePlayerController - objective-c

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.

Related

MPMoviePlayerController error _itemFailedToPlayToEnd while playing RTMP video link iOS 7

I am trying to play a video like:
- (void) playMovie {
NSURL *url = [NSURL URLWithString:
#"rtmp://122.129.75.174:61935/live/peghamtvX007"];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.videoController = controller; //Super important
controller.view.frame = self.view.bounds; //Set the size
[self.view addSubview:controller.view]; //Show the view
[controller play]; //Start playing
}
But it failed to play. Here is error:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
Can i play rtmp link in WebView using MPMoviePlayerController? and also help me out in this error.

developing Radio ios App

I have a problem when I test my radio iOS app on real device its working well but when the screen or the device is turned off, the radio is stopped and turn off why this happen?
and how to make activity indicator view stopped moving and hide it when the radio is open and finish loading???
(void)viewDidLoad
{
[super viewDidLoad];
timer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(uodatetimer) userInfo:nil repeats:YES];
player = [[MPMoviePlayerController alloc] initWithContentURL:
[NSURL URLWithString:#"http://46.43.64.50:8008/AJYAL.m3u"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
// player.useApplicationAudioSession=NO;
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
spinner.center=self.view.center;
[spinner startAnimating];
[self.view addSubview:spinner];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 105, 15)] autorelease];
volumeView.center = CGPointMake(152,372);
[volumeView setShowsVolumeSlider:YES];
[volumeView setShowsRouteButton:YES];
[volumeView sizeToFit];
[self.view addSubview:volumeView];
}
You need to do 2 things to enable audio playback in the background:
Add the "Required background modes" key to your Info.plist file with the "App plays audio" value.
Set the audio session category to AVAudioSessionCategoryPlayback and activate the audio session:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
To be able to have it playing in background you need to enable in project .plist file UIBackgroundModes or Required Background Modes in human readable format and in array for first string row write audio. That will make your app running after the screen is off and while in background.
in the yourProject-pList add this row

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;

MPMoviePlayerViewController not showing volume slider?

I am playing the video from the url:
MPMoviePlayerViewController *m = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
if([m.moviePlayer respondsToSelector:#selector(setAllowsAirPlay:)])
m.moviePlayer.allowsAirPlay = YES;
[self presentMoviePlayerViewControllerAnimated:m];
It is playing, but there is no volume control slider. Is it possible to add volume control?
You can use MPVolumeView object.
volume = [[MPVolumeView alloc] initWithFrame: rect];
[self addSubview:volume];