Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 video in UIWebview Orientation landscape

I have an iPhone application where every view is in portrait. I have a UIWebview with some HTML in it. Amoung that there is a html5 tagged video. When I play that video, it plays in portrait only. In order to make it work in landscape I have to return YES for shouldAutorotateToInterfaceOrientation in the viewcontroller, but I don't want the viewcontroller to rotate to landscape. I only want the video to support landscape orientation.

It is possible?

Thanks!

like image 280
Peter Avatar asked Aug 23 '10 23:08

Peter


2 Answers

I have the same problem, interestingly though if you use embed tags instead of video tags it works but you dont get the nice image!

<embed src='yourmovie.mp4' width='280px'></embed>
like image 121
user609906 Avatar answered Sep 28 '22 08:09

user609906


if you have javascript available to you or some other scripting engine, have you tried giving the video element and embed element an id attribute and accessing the DOM using javascript to tweak the attributes?

<body>
<video id="myvideo" width="240" height="320" src="a.vp8">
    <embed id="myvideoe" width="240" height="320" src="a.vp8">
</video>
<script type="text/javascript">
if (window.screen.width < window.screen.height) {
    //portrait
    document.getElementById('myvideo').setAttribute('width', 240);
    document.getElementById('myvideo').setAttribute('height', 320);
    document.getElementById('myvideoe').setAttribute('width', 240);
    document.getElementById('myvideoe').setAttribute('height', 320);
} else {
    //landscape
    document.getElementById('myvideo').setAttribute('width', 320);
    document.getElementById('myvideo').setAttribute('height', 240);
    document.getElementById('myvideoe').setAttribute('width', 320);
    document.getElementById('myvideoe').setAttribute('height', 240);
}
//or simply do this if you have differing size target screens:
//you can always subtract out the space for the controls.
document.getElementById('myvideo').setAttribute('width', window.screen.width);
document.getElementById('myvideo').setAttribute('height', window.screen.height);
document.getElementById('myvideoe').setAttribute('width', window.screen.width);
document.getElementById('myvideoe').setAttribute('height', window.screen.height);
</script>
</body>

if you are talking about changing the src to an entirely different video that is landscape or portrait, that is possible too. I think this might be possible only with PhoneGap which provides javascript.

like image 38
Jim Michaels Avatar answered Sep 28 '22 06:09

Jim Michaels