I am using the MPMoviePlayerController to play the video files in my application, videos are playing nice. But suddenly I opened one file and the MPMoviePlayerController opens in complete black screen, no controls are there. But I can see that there is a problem in my file and I resolved it.
I wonder is there any event that will be sent like MPMoviePlayerDidExitFullscreenNotification for these black screen issue. I tried with MPMovieSourceTypeUnknown event which seems to be not correct and tried with many events.
Now I want to know , is there any event will be sent , when the MPMoviePlayerController trying to open a file which results in black screen.
The documentations are fairly descriptive, though I will assume a black screen is a loading error:
MPMovieFinishReason Constants describing the reason that playback ended.
enum
{
MPMovieFinishReasonPlaybackEnded,
MPMovieFinishReasonPlaybackError,
MPMovieFinishReasonUserExited
};
typedef NSInteger MPMovieFinishReason;
Constants:
MPMovieFinishReasonPlaybackEnded
The end of the movie was reached.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieFinishReasonPlaybackError
There was an error during playback.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieFinishReasonUserExited
The user stopped playback.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
These are passed through the MPMoviePlayerPlaybackDidFinishNotification notification with the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey key.
Related
I have an app that shows list of movies in a table view. When I play them one after another on device it works just great. But when I switch to Apple TV over AirPlay it doesn't work anymore. It play's the first video on ATV ok but after a switch to the next video the screen on ATV start blinking/flickering and after a few seconds it falls back playing on a device. I am using MPMoviePlayerController for playing stream videos.
I also found out that if previous video finished playing over AirPlay it tries to start the next one over AirPlay also. Is this intended behaviour?
Is this kind a related with property allowsAirPlay?
I think I've found a solution. Before you switch playing another video you should stop the previous one:
[self.moviePlayer stop];
This is not needed if you are not playing via AirPlay cos the next video will automatically stop previous one by nature - you can not play two videos at once.
But If you do play video over AirPlay you need to stop previous one first and than play the next one.
This solution works for me.
I am working with a media player, some media does not have the right to be played over Airplay, don't ask why :). So when I get that media, I set
movieplayerController.allowsAirplay = NO;
If you were playing with airplay before, it is then on by default next time. By doing the code above, you will get the movie playing on your device, but the sound audio route is still sent over airplay. I have tried to overwrite the audio route, but it doesn't budge, seems like Airplay trumps all.
If I could just disable airplay, my problem would be solved, but I can't find anywhere a way to do that.
This looks similar to this question. The answer mentions that the AirPlay button should always be visible to send audio.
I'm working on a music visualizer for the iPhone/iPad, under iOS 3 you could double-tap the home button and get iPod controls. With the latest version 4.1-4.2, these controls are now grayed out when the home button is pressed. I found a similar complaint at http://openradar.appspot.com/8696944, although there wasn't a solution.
I have the base sound category set to kAudioSessionCategory_PlayAndRecord, with kAudioSessionProperty_OverrideCategoryMixWithOthers set to true. (Just to add more fun to the problem I'm using OpenAL for some sound effects.)
I have tried setting the category back to ambient when the application goes into the background. but either it happens too late or it's not sufficient.
Here's where I've got to so far:
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
devicetwo = alcOpenDevice(NULL);
contexttwo = alcCreateContext(devicetwo, 0);
//The following two lines are the lines that gray out iPod controls:
alcMakeContextCurrent(contexttwo);
AudioSessionSetActive(YES);
The iPod controls remain grayed out even once the app quits... And removing the two culprit lines of code result in no sound being produced in the app.
Well I've given up.. I'm now coding my own UI based off of the AddMusic example code
http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40008845-Intro-DontLinkElementID_2
I'm happy to report that play and stop via the MPMusicPlayerController doesn't seem to conflict with the play and record session settings. And building your own play/pause/FF seems to be fairly straightforward
p.s. I've also discovered that this Music Visualizer app: http://itunes.apple.com/us/app/music-visualizer/id337651694?mt=8 is just this addMusic sample uploaded and this guy is charging 2 bucks for it.. It's got awful reviews.. but it still seems wrong that it's on the app store.
My iPod touch 4G is running iOS 4.2, and it doesn't have this problem. I would attempt to contact Apple.
I have a UIWebview within a UIScrollView. Within the webview I have an embedded YouTube movie. When I play the YouTube movie everything works fine, however, when I press the fullscreen button the movie starts playing behind the webview. Bringing the WebView to the front does not work, because I want the scrolling capabilities of the ScrollView to do horizontal scrolling.
Basically, you want to be able to detect when a movie starts playing fullscreen and arrange your views appropriately. Then, when the fullscreen playback ends you want to be able to get your views back to how they are.
The problem is there's no documented way to hook into or detect when a UIWebView triggers video playback in full screen.
I said 'documented way', because there are some notifications you can use to detect when a UIWebView triggers fullscreen playback. You can just listen out for them and rearrange your views accordingly. However, I don't necessarily recommend this, because they're undocumented and subject to change (in fact, they have a spelling mistake in them up until iOS 4.3, see answers below).
// For iOS 4.3 and above:
UIMoviePlayerControllerDidEnterFullscreenNotification
UIMoviePlayerControllerDidExitFullscreenNotification
// For iOS 4.2 and below:
UIMoviePlayerControllerDidEnterFullcreenNotification
UIMoviePlayerControllerDidExitFullcreenNotification // (note spelling mistake)
Finding these out was a bit of a pain - there are actually several more notifications that get triggered when a YouTube video in a UIWebView gets played back. To find them out you'll need to drop a breakpoint on all posting of notifications, and then manually inspect the memory locations of those notifications to figure out their string names. I don't actually think anyone has pulled these out before, because when I google them I get nothing. But they do work, promise!
I hope being able to get notified when the fullscreen playback is entered/exited will be helpful, with the massive caveat that Apple could change this undocumented behavior at any time. Your app won't get rejected outright for using them (because you're not calling any undocumented methods), and I've used it in shipping apps. But it's still not the best idea in the world...may be the only option you have though.
Edit: To clarify, based off the comment below: they're not constants, so you'd need to put them in quotes if you were registered for notifications.
For iOS 4.3+, Apple have changed the names of these notifications:
UIMoviePlayerControllerDidEnterFullcreenNotification now is UIMoviePlayerControllerDidEnterFullscreenNotification
UIMoviePlayerControllerDidExitFullcreenNotification now is UIMoviePlayerControllerDidExitFullscreenNotification
Please pay attention: The term "Fullcreen" has changed to "Fullscreen".
Thanks!
Just wanted to confirm that this works after playing around with it for awhile. You can get direct access to the view that the video is playing in. This is a blocks method of registering for the notification and pulling out the pertinent views.
Notice: You will need to delay adding subviews and/or access Apple internal subviews to remove the navbar for further customization.
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UIMoviePlayerControllerDidEnterFullcreenNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note){
MPMoviePlayerController *theMovieController = [note object];
UIView *theDestinationVideoView = [[note userInfo]
objectForKey:#"UIMoviePlayerControllerFullscreenViewUserInfoKey"];
}];
I have an app that's worked since version 2.0 of the SDK where I create and add a UIWebView and then load the URL of an .mov to play a movie. Ever since the early version of the 4.0 beta up until the 4.0 GM this has stopped working. When I load a movie now I get the following error: :Plug-in handled load" and the movie never displays.
Is this a known issue? Am I doing something wrong in 4.0?
I figured this out. It appears to be an issue with iOS4 not being backward compatible with a UIWebView created with 'init' rather than 'initWithFrame'. In 2.0 - 3.1.3, you could only show video in a UIWebview as full screen. I think this is why it didn't matter if you called 'init' -- the movie player would kick in and go fullscreen. However, in 3.2 and higher you can now inline video in a UIWebView so you have to call initWithFrame and give it something like [[UIScreen mainScreen] bounds] so there's a visible view. Not quite sure if this is bull or not but seems to be the case.
I got a situation of "this movie could not be played" when playing a video clip.
This happened when recorder was just used. And this would NOT happen when player was just used.
Then I set audio session category to kAudioSessionCategory_AmbientSound after recorder finished.
This problem was solved after I did that.
Simply just ignore it. No harm in doing so.
if (![error.localizedDescription isEqualToString:#"Plug-in handled load"])
At least in PhoneGap's ChildBrowser, the didFailLoadWithError method handles and displays this message. Simply don't display the error, problem solved, but in this specific case there are two 'done' buttons to press before you get back to the application.