Playing videos in UIWebView broken in iOS4? - iphone

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.

Related

MPMoviePlayerController goes into black screen

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.

iPad SDK: Embedded YouTube movie plays fullscreen version behind UIWebView

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

Play two videos with MPMoviePlayerView Controller

I am developing an application for IPAD and I need to play two videos one after another but can not find how. I'm using MPMoviePlayerViewController to do it and do not know how to launch a share after the first video to be played and start the second. Can someone help?
what about using MPMoviePlayerPlaybackDidFinishNotification from documentation ?
In that method:
[..] you can also change the currently playing movie by changing the value in the contentURL property. [..]
(still from documentation)
hope it helps

how to know that MPMoviePlayerController is playing in Iphone OS 3.0

I need to know if at an specific moment the MPMoviePlayerController is playing.
In iphone 3.0 it is not firing the MPMoviePlayerContentPreloadDidFinishNotification.
Does anyone knows any solution?
Thanks in advance!
So thanks for the answer.
I fix this so I will post the answer.
The answer is that MPMoviePlayerContentPreloadDidFinishNotification is NOT FIRED if you invoke play() right after the initialization.
To have MPMoviePlayerContentPreloadDidFinishNotification which works ok you have to invoke the "play()" method of the MPMoviePlayerController when the MPMoviePlayerContentPreloadDidFinishNotification is fired ( I mean in the MPMoviePlayerContentPreloadDidFinishNotification method ). In this case it always works.
Tested on 3.0, 3.1 and 3.1.2
Same question (but no answer) here and several other reports can be found on other sites (e.g. here)
Not ideal, but it seems targeting 3.1 solves the problem.
A workaround maybe to set the MPMoviePlayerController property scalingMode to something other than the default MPMovieScalingModeAspectFit ( e.g. MPMovieScalingModeNone and make sure your video is correct size) before calling play and then hook the MPMoviePlayerScalingModeDidChangeNotification event instead. it seems to get called (more than once!) as soon as the movie starts playing. Of course it will also be called if the user changes the scaling mode manually, so code for this. It's dirty but may help you?

iPhone. Is it possible to load a video file and select a specific frame?

Is it possible to load a short video file and - once loaded - select a specific frame and display that frame in a view? If there is no native support for this, how about an open source alternative?
Thanks in advance.
-Doug
I think that in iphone programming you're stuck with the fullscreen video solution proposed by apple. You could write your own controller to do it differently, but i think it could be difficult to achieve good performances and you're cut out of the app-store for sure.
edit:
looks like in iphone sdk 3.2 apple added something for you:
The MPMoviePlayerController class
defines an interface for managing the
playback of a movie. Playback occurs
either in full-screen mode or in a
custom view that is vended by the
movie player controller. You can
incorporate the view into your own
view hierarchies or use a
MPMoviePlayerViewController object to
manage the presentation for you.
and again
Behavior in iPhone OS 3.1 and Earlier
In iPhone OS 3.1 and earlier, this
class implemented a full-screen movie
player only. After creating the movie
player and initializing it with a
single movie file, you called the play
method to present the movie. (The
definition of the play method has
since moved out of this class and into
the MPMediaPlayback protocol.) The
movie player object itself handled the
actual presentation of the movie
content.
i haven't tested it yet but have a look at the official documentation under MPMoviePlayerController Class Reference, it may help.