i have a piece of flash that doesn't want to play in internet explorer:
<div class="flash_slider">
<object style="visibility: visible;" id="flashcontent" data="/files/theme/piecemakerNoShadow.swf" type="application/x-shockwave-flash" height="460" width="980">
<param value="transparent" name="wmode">
<param value="xmlSource=/files/theme/piecemakerXML.xml&cssSource=/files/theme/piecemakerXML.css&imageSource=/files/theme/" name="flashvars">
</object>
<script type="text/javascript">
var flashvars = {};
flashvars.xmlSource = "/files/theme/piecemakerXML.xml";
flashvars.cssSource = "/files/theme/piecemakerXML.css";
flashvars.imageSource = "/files/theme/";
var attributes = {};
attributes.wmode = "transparent";
swfobject.embedSWF("/files/theme/piecemakerNoShadow.swf", "flashcontent", "980", "460", "10", "/files/theme/expressInstall.swf", flashvars, attributes);
</script>
</div>
any ideas?
thanks
Target IE using conditional comments.
<!--[if !IE] >
<script type = "text/javascript" >
var flashvars = {};
flashvars.xmlSource = "/files/theme/piecemakerXML.xml";
flashvars.cssSource = "/files/theme/piecemakerXML.css";
flashvars.imageSource = "/files/theme/";
var attributes = {};
attributes.wmode = "transparent";
swfobject.embedSWF("/files/theme/piecemakerNoShadow.swf", "flashcontent", "980", "460", "10", "/files/theme/expressInstall.swf", flashvars, attributes);
</script>
<![endif]-->
As you are loading flash through SWFObject, it will ensure that your script won't run in IE.
Also try browser sniffing. ( Not recommended, but I dont see any other way here )
var isMSIE = /*#cc_on!#*/false;
if(!isMSIE){
var flashvars = {};
flashvars.xmlSource = "/files/theme/piecemakerXML.xml";
flashvars.cssSource = "/files/theme/piecemakerXML.css";
flashvars.imageSource = "/files/theme/";
var attributes = {};
attributes.wmode = "transparent";
swfobject.embedSWF("/files/theme/piecemakerNoShadow.swf", "flashcontent", "980", "460", "10", "/files/theme/expressInstall.swf", flashvars, attributes);
}
If that does not work, try
var isMSIE = navigator.appName === 'Microsoft Internet Explorer';
This might help you: http://pipwerks.com/2011/05/18/sniffing-internet-explorer-via-javascript/
Related
<script type="text/javascript">
function random_playlist(){
var myrandom=Math.round(Math.random()*4);
var soundurl='http://dummy.xy/dummy.mp3';
if (myrandom==0){soundurl='http://path_to.mp3';}
else if (myrandom==1){soundurl='http://path_to.mp3';}
else if (myrandom==2){soundurl='http://path_to.mp3';}
else if (myrandom==3){soundurl='http://path_to.mp3';}
else if (myrandom==4){soundurl='http://path_to.mp3';}
console.log(soundurl);
return soundurl;
};
</script>
<audio id="audioplayer_id" controls="controls" loop>
<source id="source_id" src="" type="audio/mp3"/>
Your browser does not support the audio element
</audio>
<script type="text/javascript">
var audioload = random_playlist();
console.log(audioload);
document.getElementById('source_id').src= audioload;
var audioplayer_id = document.getElementById('audioplayer_id')
audioplayer_id.volume = 0.15;
audioplayer_id.load();
audioplayer_id.play();
</script>
Works well for me but can it be optimized or is this OK ?
I just hacked this together from various sources seems like html5 didnt integrate a playlist function in the audio tag, which seems funny to me.
greets
You could shorted the random_playlist function like this:
function random_playlist(){
var PATHS = ['http://path_to.mp3', 'http://path_to.mp3', 'http://path_to.mp3'];
return PATHS[Math.floor(Math.random() * PATHS.length)];
}
or (a better but more complicated version):
var random_playlist = (function(){
var PATHS = ['http://path_to.mp3', 'http://path_to.mp3', 'http://path_to.mp3'];
return function(){
return PATHS[Math.floor(Math.random() * PATHS.length)]
};
}())
I am creating the below url request which launches a flex application through the mentioned url. I have also added data and set url req method to POST. How can I read this POST data in my Flex Application which is being launched
var urlReq:URLRequest = new URLRequest();
var requestVars:URLVariables = new URLVariables();
requestVars.id = 'abc';
urlReq.data = requestVars;
urlReq.method = URLRequestMethod.POST;
urlReq.url = '../../bin-debug/FlexApp.html';
navigateToURL(urlReq);
Could you pass your variables within the url and then use flashvars via swfobject to pass them to the target app?
I've had more or less similar issue, and used this method.
In my first swf:
var urlReq:URLRequest = new URLRequest(String("game.html?user_id="+userId+"&user_code="+userCode));
And then in game.html I parsed those variables and sent then as flashvars:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
};
var flashvars = {
user_id: getUrlVars()["user_id"],
user_code: getUrlVars()["user_code"]
};
var params = {
quality: "high",
bgcolor: "#000000",
play: "true",
loop: "true",
wmode: "window",
scale: "showall",
menu: "true",
devicefont: "false",
allowScriptAccess: "true"
};
swfobject.embedSWF("preloader.swf", "flashContent", "980", "663", "11.2.0",false, flashvars, params);
</script>
And finally in my target swf I received them like this:
var userId:String = loaderInfo.parameters.user_id as String;
var userCode:String = loaderInfo.parameters.user_code as String;
I hope this helps, and if not, then I probably didn't understand the main issue.
The POST data is sent to the server, so if you want to read it on FlexApp.html from the client then the server needs to echo it back on that page somehow. Otherwise you could use a GET request and access the request parameters using JavaScript window.location.search.
Here's an example using PHP to output the POST variables as JSON to the page:
<script>
var post_params = <? echo json_encode($_POST); ?>
function getPostParam(name){
return post_params[name];
}
</script>
Call from JavaScript:
alert(getPostParam("id"));
Call from ActionScript:
trace(ExternalInterface.call("getPostParam", "id"));
I would like to ask why can't I run two different source of video which is .ogg and .mp4 files in this canvas. I am trying to override this green screen video to another video that had it's background colour hidden.
<html>
<head>
<script type = "text/javascript">
function load() {
var get1 = document.getElementById("c1");
var set1 = get1.getContext("2d");
var get2 = document.getElementById("c2");
var set2 = get2.getContext("2d");
var video1 = document.getElementById("video1");
var video2 = document.getElementById("video2");
video1.addEventListener('play', function(){runVideo();});
video2.addEventListener('play', function(){runVideo2();});
var runVideo1 = function() {
if(video1.paused || video1.ended) {
return;
}
var frameconversion = function() {
if(window.requestAnimationFrame) {
requestAnimationFrame(runVideo1);
} else {
setTimeout(runVideo,0);
}
};
};
var runVideo2 = function() {
if(video2.paused || video2.ended) {
return;
}
var frameconversion2 = function() {
if(window.requestAnimationFrame) {
requestAnimationFrame(runVideo2);
} else {
setTimeout(runVideo2,0);
}
}
}
}
</script>
</head>
<body onload="load()" style="background:grey">
<video id = "video1" controls="true">
<source src = "video.ogg" />
</video>
<video id = "video2" controls="true">
<source src = "Helicopter Bell Fly By with Sound on green screen - free green screen 6.mp4" />
</video>
<canvas id = "c1" width="500" height="300"></canvas>
<canvas id = "c2" width="500" height="300"></canvas>
</body>
</html>
This article on Metia shows a working HTML5 example of green-screen (chroma key) video in a canvas. As you can see, it allows you two change the background to a selection of static images and video sources.
I am trying to embed my flash game inside my HTML Code.
I got the embedding right, but now I want to use GET to get the ID from the url
this is the url I use :
http://localhost/directory/html/indexpage.php?id=3
I want to get the ID of the url using the embed code :
<head>
<title> Widget </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.id = "3";
var params = {};
params.menu = "false";
params.scale = "noscale";
params.allowfullscreen = "false";
var attributes = {};
swfobject.embedSWF("flash/Flash.swf, "game", "398", "398", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
<link href="./mobile/styles/game.css" rel="stylesheet" type="text/css" media="screen" title="stylesheet" />
</head>
I tried this :
swfobject.embedSWF("flash/Flash.swf?id=3", "game", "398", "398", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
what am I doing wrong here?
Flash doesn't parse the query string, probably for good reason. You need to pass in as flashvars. It's a common annoyance -- maybe SWFObject has improved since I last had to do this stuff (2012), but if not, I would tend to have code like this:
function parseQueryString() {
var query = window.location.search.substring(1);
var keyVals = query.split("&")
var dict = {}
for (var i=0; i<keyVals.length; i++)
{
var pair = keyVals[i].split("=");
dict[pair[0]] = unescape(pair[1]);
}
return dict;
}
...
flashvars = parseQueryString(); // catchall
flashvars.foo = parsedQuery.foo; // more explicit is probably better
...
swfobject.embedSWF(
"MyFlashThing.swf", "flashContent",
"800", "600",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
I need to autoplay an inlined video from youtube in uiwebview with IOS 5.0+.
I managed to make it play inlined with this:
NSString *html = [NSString stringWithFormat:#"\
<html>\
<head>\
<script type='text/javascript'>\
function onPlayerReady(event) {\
event.target.playVideo();\
}\
</script>\
<style type=\"text/css\">\
iframe {position:absolute; top:0%%; margin-top:-0px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"100%%\" src=\"https://www.youtube.com/embed/%#?feature=player_detailpage& modestbranding=1&rel=0;autoplay=1;showinfo=0;loop=1;autohide=1;playsinline=1;autoplay=1\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", ID];
[videoWebView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
But i cant figure out how to make it auto play.
I also found other solution which auto plays the video but it starts in fullscreen, and i dont know how to make it inlined.
NSString *youTubeVideoHTML = #"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head>
<body> <div id=\"player\"></div>
<script> var tag = document.createElement('script');
tag.src = \"http://www.youtube.com/player_api\";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {width:'%d', height: '%d', videoId:'%#', events: { 'onReady': onPlayerReady, } }); }
function onPlayerReady(event) { event.target.playVideo(); }
</script>
</body> </html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, 320, 150, ID];
[videoWebView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
Is there a way to make js version inlined or first version autoplay? Or is there some other solution to this?
I finally found it.
In JS version you can specify player parameters (like "showinfo", "rel" and of course "playsinline" )
You just need to add playerVars object and specify your parameters in it.
So the code would look like this:
NSString *youTubeVideoHTML = #"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', {width:'%d', height: '%d', videoId:'%#', playerVars: {'playsinline' : 1, 'rel':0, 'showinfo':0}, events: { 'onReady': onPlayerReady, } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, 320, 180, ID];
[videoWebView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
Why you are not using native Video Player?
Try LBYouTubeView wrapper, it is very easy to integrate.