play two video in iPhone simultaneously - iphone

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.

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];

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
}

MPMoviePlayerViewController stops playback when unplugging headphones

I'm currently developing a web-tv application that uses MPMoviePlayerViewController resp. MPMoviePlayer to playback streaming video content on the iphone.
the issue I've got here is that once i unplug my headphones (while watching tv) the player stops.
Due to the fact that I'm not showing the standard controls (previous button, play/pause button, next button) but my custom controlls, the user is stuck with the frozen picture unless he switches to a new channel..
is there any way to detect a playback interuption caused by unplugging the headphones?
thanks for your tipps and tricks in advance,
sam
I don't have a direct answer to your question. But I think MPMoviePlayerPlaybackStateDidChangeNotification will be good enough to solve your issue. Once you are notified, Get the playback state from the playbackState property of the movie player object and take appropriate action.
Elaborating on the accepted answer with some code:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(videoPlaybackStateChanged:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:moviePlayer];
- (void)videoPlaybackStateChanged :(NSNotification *)notification
{
if (moviePlayer != nil && [moviePlayer playbackState] == MPMoviePlaybackStatePaused)
{
[moviePlayer play];
}
}

How to add another video to MPMoviePlayer?

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.

writing an iPhone application with embedded video

I am researching video streaming for an iPhone application that I may have to write in the near future. The application does a whole lot other than stream video, but video aspect is the part that I have no experience with.
Anyone know of any good articles on writing streaming video apps?
Google seems to inundate me with links that have everything not to do what I seek.
Thanks,
m
Apple provide good documentation on the media framework i ntheir docs.
Search for MPMoviePlayerController. The following sample code plays a movie from a URL. (disclaimer, this code lifted from Apple).
-(void)playMovieAtURL:(NSURL*)theURL
{
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
theMovie.scalingMode=MPMovieScalingModeAspectFill;
theMovie.userCanShowTransportControls=NO;
// Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Release the movie instance created in playMovieAtURL
[theMovie release];
}
I am looking at this issue as well. I would like to embed a video in an iPad app, something like how the Associated Press iPad application handles videos.
Apparently you can do this type of embedded video in OS 3.2 and later. Apple's documentation for MPMoviePlayerController describes how this can be done:
http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html