Notification after Video playback in mobile safari - iphone

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.

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 perform different actions for the done button and the video player finish method of embedded youtube webview in iPhone

I am new to iPhone. Please help me in solving this issue:
I have embedded YouTube webview in Iphone. My problem is when clicking the done button of YouTube I want to call a class and when the video finishes playing an different class should be called. Can anybody help me on identifying what are the methods called on click of done button and finish of YouTube player in iPhone?
Thanks
If the video is played in UIWebView then you can access when the video is played and when Done button is pressed using the following code along with the code you have used to load url in webview
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
//For Done Button
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
And it can be accessed through
BOOL isVideoInFullScreenMode;//Temperory added here.. must be in .h file or at teh top if required
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
isVideoInFullScreenMode = YES;
}
-(void)videoPlayFinished:(NSNotification *)notification{
//Your stuffs here
isVideoInFullScreenMode = NO;
}
You are in a UIWebView, so the done button isn't related to your application: pressing the button will never call your application.
The only method you have are from UIWebViewDelegate and they are:
webView:shouldStartLoadWithRequest:navigationType:
webViewDidStartLoad:
webViewDidFinishLoad:
webView:didFailLoadWithError:
If you have to know when player finish, I suggest you to try this class: LBYouTubeView, it will play youtube video on your player component, so you can use Player delegate's method to to do what you asked for.

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.

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