开发者

Can i play video in portrait mode?

Can anybody explain me how to play video in portrait mode in ipho开发者_如何学Cne device. It will be very helpful to if you provide some sample code for referance. Thanks in advance.


If you want to show your movie in portrait mode using MPMoviePlayerController, it is better to get your video rotated by 90 degree so that it always play in Landscape mode but appears to the user as it is playing in Portrait mode...

I have gone through so many tricks and found the above as best alternate.


What do you want to be in portrait orientation? Video itself you can rotate any which-way when you're creating it; the overlay controls, though, you can't really do anything with within the boundaries of the SDK.


My suggestion would be to rotate the video so that if it was being played in landscape and the device was turned to portrait, it would be oriented correctly. From there, you could disable the controls (so tapping the screen doesn't bring up the video controls) if you don't need them. That way the user wouldn't know that the player is actually landscape.

Edit: Try this code from this thread over at iPhoneDevSDK; I don't know if it will work since I haven't used it, though:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];

[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];

Edit: Whoops! As I read further in the thread, Apple considers that method a private API and will probably reject your app for using it. You could try, though.


Simplest method is to use UIWebView to play the video, as it supports both orientations.
Here's some sample code (note: the webview will spawn a new modal view for the video to play in, so I size it at zero x zero):

if( !webView )
{
   self.webView = [[[UIWebView alloc] initWithFrame:CGRectZero] autorelease];   
   [self.view addSubview:webView];
}

NSURL *url = [NSURL URLWithString:@"http://myserver.com/movie.m4v"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜