I want to add an overlay view for my video when the video is paused by the user. Is there any way to get the pause notification from MPMoviePlayerController?
According to Apple Doc, there should be ways to do this but I can't find which notification should I use for this purpose.
Quote:
In addition to being notified when
playback finishes, interested clients
can be notified in the following
situations:
-When the movie player begins playing, is paused, or begins seeking forward
...
For more information, see the Notifications section in this reference.
I assume you know about delegates and protocols as a means of receiving callbacks?
There's another global mechanism called notifications too.
You can do this via
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateChanged)
name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
Then, within playbackStateChanged, you can fetch the playbackState
- (void) playbackStateChanged {
_player.playbackState; // reading the playback
}
The step of reading playbackstate directly from the player is specified in the docs
To get the current playback state, get the value of the playbackState property of the movie player object.
Related
I am having a difficulty with the MPMoviePlayViewController.
I insatiate the controller, assign the url and show the player using:
[self presentMoviePlayerViewControllerAnimated:[appDelegate movieController]];
Then when the movie finished I dismiss it:
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self dismissMoviePlayerViewControllerAnimated];
The movie player is alloc in my AppDelegate.
There are some other listeners on MPMoviePlayerPlaybackDidFinishNotification. This is for the case where there might e.g. only be audio and it shows a play/pause button and counters in table cells.
The problem is that when I load a second movie in the same MPMovieViewController, it appears fine but the controls are not working correctly. They are work as long as they are visible, but as soon as they disappear there is no may of getting them back and therefore to dismiss the movie player.Sometimes closing and opening the App works, but sometimes it doesn't and I need to 'kill' the App in order to be able to start again.
Is there a way to play subsequent video's in the MoviePlayer while the controls still work?
Any suggestions how to 'reset' the Player in a way that I can prevent the other listeners from given a DEALLOC as they are listening for the action?
you dont need to dismiss the player you just need to set the new url... or maybe I missunderstood your problem...
Try adding this to your setup movie player controller
moviePlayerController.view.userInteractionEnabled = YES;
I would like to track the last position of a media item (song or podcast). I can access the total duration using the MPMediaItemPropertyPlaybackDuration property of the MPMediaItem. I am interested in way to store and track the last played position.
Does every player do this on their own ? Would I get it for free if I just play entities with the MediaPlayer ?
I have not hooked media player to play items yet, I would like to understand if I need to implement my own bookmarking method.
[audioPlayer currentPlaybackTime]
Will give you the current playback time. I have a resume feature on a podcast player and I simply watch for interruptions with:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playPlaybackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.audioPlayer];
and then inside that callback function, check the state:
if(self.audioPlayer.playbackState == MPMoviePlaybackStateInterrupted)
and record the playback time on interruption...
I am writing a music playlist editing application for the iPhone.
I am subscribing to the MPMusicPlayerController
MPMusicPlayerControllerNowPlayingItemDidChangeNotificationand I am
getting a problem where the #selector method for this notification
is being called more than once when the nowPlayingItem: changes.
I have divided up each playlist into their own MPMediaItemCollection objets, and when one playlist is finished I load the next one, by calling -pause on the player, passing a new MPMediaItemCollectionto the music player controller via its -setQueueWithItemCollection: method. I then explicitly set the nowPlayingItem to an item of item of my own and finally I call -play.
[musicPlayer pause];
[musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[selectedPrefs mediaItems]]];
musicPlayer.nowPlayingItem = [selectedPrefs.playbackItems objectAtIndex:selectedPrefs.nowPlayingIndex];
[musicPlayer play];
When I do this the #selector is called twice for the now playing item changing. I suspect this is because -setQueueWithItemCollection:automatically changes the now playing item to point to the first media item in the new collection, and then I am changing this item again before calling -play.
Many thanks.
I want to play two video in iPhone simultaneously.
There are two way to play video in iphone, One is use AVQueuePlayer. but in this controller I don't get how get the video playing is completed and how to restart video again.
Another way is MPMoviePlayerController . but in this controller I don't get how to seek video at particular time and also it is not able to play two video simultaneously as the AVQueuePlayer is able to play.
as a solution i am using AVQueuePlayer to play video and but can any one help me to restart video and get method to detect end point of the video. or know any other api to so this
Thanks in advance.
I have found the solution to play two video . You can use AVQueuePlayer to play video. Using this controller you can play two video at the same time .
I wonder if this is even possible. Video playback on the iPhone is ensured thanks to a hardware video decoder. And I really think the hardware decoder can only handle one video stream at a time.
Ecco is correct. You're limited to one video at a time due to hardware restrictions.
However, if you're after 7KV7's suggestion of one video ending and triggering the playback of another, you can make use of the MPMoviePlayerPlaybackDidFinishNotification notification in the following way:
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(firstMoviePlayerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void)moviePlayerDidFinish:(NSNotification *)notification {
if (firstMovie) {
[moviePlayerController setContentURL:nextMovieURL];
[moviePlayerController play];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}
Also, note that you can find the current playback point in a MPMoviePlayerController instance by examining the currentPlaybackTime property.
I have made a music app using avtouchController & I want to play my next song one after the other using autoplay can u please give me the step to autoplay a song.
It's hard to tell from your question, but it sounds like you want to use AVQueuePlayer.
You should go to settings and set the play mode as sequential play mode.
If you're using AVFoundation, you can just add a listener to your player, and make the end playback method to fetch the next track. You add the listener like so:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
And then you create your method, something like this:
-(void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *p = [notification object];
//Fetch your next track from your plist, array, database or whatever
}