Skip to content

Instantly share code, notes, and snippets.

@isseium
Created September 6, 2014 12:57
Show Gist options
  • Save isseium/9c70a303531b60148b80 to your computer and use it in GitHub Desktop.
Save isseium/9c70a303531b60148b80 to your computer and use it in GitHub Desktop.
WebView に表示した Video タグをオートプレイ設定する方法 ref: http://qiita.com/isseium/items/18b4c78e6e450310922a
$.webview.url = "video.html"
<Alloy>
<Window class="container">
<WebView id="webview" />
</Window>
</Alloy>
<!DOCTYPE html>
<html>
<head>
<script src="http://www.google.com/jsapi"></script>
<script>google.load("jquery", "1.3");</script>
<script type="text/javascript">
jQuery.noConflict(); var j$ = jQuery;
function fakeClick(fn) {
var $a = j$('<a href="#" id="fakeClick"></a>');
$a.bind("click", function(e) {
e.preventDefault();
fn();
});
j$("body").append($a);
var evt,
el = j$("#fakeClick").get(0);
if (document.createEvent) {
evt = document.createEvent("MouseEvents");
if (evt.initMouseEvent) {
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
}
j$(el).remove();
}
j$(function() {
var video = j$("#my-video").get(0);
document.getElementById("my-video").playbackRate = 1;
fakeClick(function() {
video.play();
});
});
</script>
</head>
<body>
<video id="my-video" width="340" height="273" src="filename.mp4" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment