How to add another video to MPMoviePlayer? - iphone

Is it possible to make a playlist for MPMoviePlayer? all videos are from internet.
While player runs, when it comes to 1 minute position i want to play another video from URL.
second video is an ads clip. after ads clip finishes, main video should continue.
is it possible? i saw some ipad apps, like hulu plus.
what steps should i make?

You can use the playbackdidfinish notification:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
And make your player fetch the next item in your playlist with this method
-(void)moviePlayBackDidFinish:(NSNotification*)notification;
You can save the url's in a plist file and keep track of the current item beign played using a simple integer index.

Related

Is it possible to interject your own audio once the ios media library has taken over?

I am wondering if it would be possible to insert your own audio once the ios media library has taken over in an app?
Example: Playing a piece of audio after every song that says the number of songs you've listened to that day.
I know that because its a framework there is only so many things they let you do.
This should be doable. To start, you can add your class as an observer of the MPMusicPlayerControllerNowPlayingItemDidChangeNotification to be informed when the song in the iPod library changes. From there, you can tell the iPod library to pause, play your track, and then resume music playback afterwards.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(someSel:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:nil];
[[MPMusicPlayerController iPodMusicPlayer] pause];
// play your sound
[[MPMusicPlayerController iPodMusicPlayer] play];

Tracking the position of a half played media item on iPhone/iPad

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...

play two video in iPhone simultaneously

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.

Notification after Video playback in mobile safari

I am trying to play some videos in a UIWebView and required to get some feedback when the video playback is finished, without any user interaction. I am looking for something similar to MPMoviePlayerPlaybackDidFinishNotification, but in UIWebView. Appreciate if anyone can share a work around.
I can't vouch for all video types but when I play a YouTube video in a UIWebView I can capture the event when the user presses 'Done' by subscribing to a private notification type:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerDidExitFullscreen:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
This works in iOS 4.3 and 5.0.

how to autoplay next song in music application when first song completes playing

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
}