adding timer to mpmovieplayerviewcontroller - iphone

I am using MPMoviePlayerViewController for playing the sound and video. I am streaming the song from the url. It is working fine.But the problem is, MPMoviePlayerViewController is not showing the time progress for the song I playing. That bar is disabled. How to make the time progress bar active? I have following code to play the song.
mediaPlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:songUrl];
[self presentModalViewController:mediaPlayerController animated:YES];
[[mediaPlayerController moviePlayer] play];

If you want to show the current progress time on your own custom way, you can show it by using the currentPlaybackTime property in the MPMediaPlayback protocol gives you that info.

U use AVPlayer for playing live streaming. Refer this link.
Also refer StitchedStreamPlayer link sample code by apple.
Set controlStyle for mediaPlayerController:
[mediaPlayerController moviePlayer].controlStyle = MPMovieControlStyleFullscreen

Related

Open movie stream in another view

I have in my app a tab view with many tabs, and in one of them I have a button that when is clicked, I want to show a movie stream in a view. I have this code:
NSString *moviePath = #"http://10.0.0.4/prog_index.m3u8";
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))];
theMovie.view.backgroundColor = [UIColor grayColor];
theMovie.view.tag = 9999;
[self.view addSubview:[theMovie view]];
[theMovie play];
The view appears, but the video doesn't start. What is wrong?
You're passing to the MPMoviePlayerController an URL pointing to a m3u8 file. That is a playlist. To play media with MPMoviePlayerController, you have to set it an actual video file. You should parse the playlist to get the link to the real video and then init your MPMoviePlayerController with the real link.
Check M3U - Wikipedia and MPMoviePlayerController reference
Also check this related question
EDIT: Thanks to Hugo Silva, I realized that MPMoviePlayerController is able to play live streams in m3u8 format, since I've not seen anything wrong in your code, I suggest you to check if it's a problem of your stream. Try using one of the samples provided by Apple. Also make sure that your stream meets Apple's requirements for HTTP Streaming

Cannot get MPMoviePlayerController to return to my TableView

I have a table view that has a list videos. When I click on one it uses MPMoviePlayerController to play the corresponding video. I cannot figure out how to have the player return to the list-view when the video finishes or I click on the done button.
I read the documentation and they said there was a
MPMoviePlayerPlaybackDidFinishNotification.
I figure I could have code that would go off when the notification was sent to go back to my list-view, but:
I do not understand notifications. Are they like using a delegate for a call back?
After I detected the notification, how would I tell the player to go away?
If you use the MPMoviePlayerViewController then the approach is something like:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentUrl:url];
[myViewController presentMoviePlayerViewControllerAnimated:player];
You don't need to worry about the notification then. Once the user clicks done the movie player will go away.

Stop iPad MoviePlayer video when a view is changed

I'm writing my first iPad app that plays a video on a portion of the screen. My problem is that if the user changes to another view while the video is playing, the audio keeps playing in the background. I assume I have to add something to the "viewDidUnload" method but I'm not sure what to do. Any ideas? Thanks for any info.
You can try adding
[myMoviePlayer pause]; // assume myMoviePlayer is an instance variable
[myMoviePlayer stop];
myMoviePlayer = nil;
to your viewWillDisappear method.

MPMoviePlayerController questions, best practices

I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?
I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.
Here's how I create it:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
Then to play a video I do this:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
Any advice is welcome... thanks.
When you are changing the video in an MPMovieplayerController,then you can remove the mpmoviecontrollerplayer view from super view using removeFromSuperView and again add it's subview to the super view initializing it with new URL.
No need to create new object every time.

MPMoviePlayerController for iPhone App on iPad

For some reason, the expand button the arrow points to in the screenshot below causes the view controller that initiated video playback to animate back over top of the video, but without stopping video playback which means you can still hear the audio even though the video is no longer visible. I've tried other movie control styles, but there are other problems with those (for example, no controls causes the player to play the entire video before dismissing, i.e. no 'Done' button).
Here is the code that initiates the video playback:
player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[player setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:player animated:YES];
[[player moviePlayer] play];
Any ideas/suggestions as to how I can either disable that button or receive its notification so I can respond accordingly?
Thanks.
I can't find a solution to this, but I did find a workaround. I simply call [player stop]; in my -viewDidLoad of the calling view controller. The outcome won't be what the user expects when they press that button, but it's better than allowing the video to continue to play when they press it.