How to get the swf name using javascript? - actionscript-3

I have embedded a single swf three times named as video.swf.
The swfs names are video1 , video2 and video3.
If I play a swf, I wants to get the currently playing swf's name?
Is it possible ?
I'm using javascript for communication.

I had to do something very similar for work on a project for Swatch/MTV (having multiple embedded players on a page and playing only one clip at a time (playing a different clip, would pause others, etc.)
e.g.
var vids = ['video/file/72066f40bfcaea46e10460585b4e4bcb.mp4','video/file/3d5db6b87f9cdacb016c9c55afed1e08.mp4','video/file/c18b04a1a548cbf20609de70a106d7cc.mp4','video/file/4568a11f3f6a7ff467a85fefe2ac08e6.mp4','video/file/b91081d37a81692194c0e34580958c51.mp4']; for(var i = 0 ; i < vids.length; i++){
var flashvars = {};
flashvars.video_url = 'http://www.swatchmtvplayground.com/'+vids[i];
flashvars.video_id = i;
flashvars.locale = "gb";
flashvars.skin = 'upperBackground:0xf8c3c4,lowerBackground:0xe2e2e2,generalControls:0x000000,slider:0xb58f8f,progress:0xe2e2e2';
var params = {};
var attributes = {};
attributes.id = "mediaplayer"+i;
so = swfobject.embedSWF("http://www.swatchmtvplayground.com/flash/mediaplayer/mediaplayer.swf", "mediaplayer"+i, "578", "345", "10.0.0", false, flashvars, params, attributes);
}
function pauseAllPlayers(exceptThisOne){
for(var i = 0 ; i < vids.length ; i++) if(exceptThisOne != "mediaplayer"+i) document.getElementById("mediaplayer"+i).pause();
}
to get the id I've used a neat little trick I didn't previously know about (executing JS created with actionscript) using Zeh Fernando's excellent guide: Getting the SWF’s HTML object/embed id from within the Flash movie itself
HTH

If you're using the same swf file three times you'd have to pass in a flash var to let the swf know which instance it is (video1, video2, or video3). Then when a video.swf instance starts playing use AS3's ExternalInterface to call JavaScript and mark that swf instance as the one currently playing.
Using SWFObject to embed the swfs in the page you can set the flashvars in JavaScript like this:
var flashvars1 = {
name: "video1",
};
swfobject.embedSWF("video1.swf", "flashContent1", "640", "480", "10.0.0", false, flashvars1, {}, {});
var flashvars2 = {
name: "video2",
};
swfobject.embedSWF("video2.swf", "flashContent2", "640", "480", "10.0.0", false, flashvars2, {}, {});
var flashvars3 = {
name: "video3",
};
swfobject.embedSWF("video3.swf", "flashContent3", "640", "480", "10.0.0", false, flashvars3, {}, {});
Within each swf you'll now have a 'name' var that can be accessed through LoaderInfo:
var name:String = LoaderInfo(this.root.loaderInfo).parameters.name;
And you call ExternalInterface from Flash like so:
ExternalInterface.call( "videoPlaying", name );
This would call a JavaScript function called 'videoPlaying' with the name as the argument:
function videoPlaying(name) {
// do something with the name arg
}

Related

progressive load and play video from base64 pieces

I have many pieces of a video in base64.
Just that I want is to play the video progressively as I receive them.
var fileInput = document.querySelector('input#theInputFile');//multiple
fileInput.addEventListener('change', function(e) {
var files = fileInput.files;
for (var i = 0; i < files.length; i++) {
var file = fileInput.files[i]
fileLoaded(file, 0, 102400, file.size);
};
e.preventDefault();
});
videoA=[];
function fileLoaded(file, ini, end, size) {
if (end>size){end=size}
var reader = new FileReader();
var fr = new FileReader();
fr.onloadend = function(e) {
if (e.target.readyState == FileReader.DONE) {
var piece = e.target.result;
display(piece.replace('data:video/mp4;base64,', ''));
}
};
var blob = file.slice(ini, end, file.type);
fr.readAsDataURL(blob);
var init = end;
var endt = init+end;
if (end<size){
fileLoaded(file, init, end, size);
}
}
Trying to display the video by chunks:
var a=0;
function display(vid, ini, end) {
videoA.push(vid);
$('#video').attr('src','data:video/mp4;base64,'+videoA[a]);
a++;
}
I know this is not the way but I`m trying to search and any response adjust to that I'm searching.
Even I'm not sure if it is possible.
Thanks!
EDIT
I've tried to play the chunks one by one and the first one is played well but the rest of them give the error:
"Uncaught (in promise) DOMException: Failed to load because no supported source was found".
If I could make the chunks to base64 correctly it's enough for me
Ok, the solution is to solve the creation of base64 pieces from the original uploaded file in the browser that can be played by an html5 player
So I've put another question asking for that.
Chunk video mp4 file into base64 pieces with javascript on browser

Adobe Animate CC- Dynamic text layer pulling from JSON or TXT file?

I've create a basic HTML5 Canvas animation in Adobe Animate CC 2015.2 with a 3 line headline. I need to be able to feed the text in from an external file to be able to change it for translating into different languages.
Is there an easy way to do this? Or should it just be standard HTML absolutely positioned on top?
I know this is an old question, but here's my solution for this as it took a while to find one that worked well.
I needed to have multiple dynamic text boxes in a series of HTML 5 animations created in Animate CC, that were used as part of a Bootstrap Carousel slide show. I wanted to be able to add in multiple languages later - so I used a json file for each language to store the text content and loaded this in on demand.
example json:
{
"1": {
"name": "default_text",
"text": {"0" : "Error locating text content for this animation?"}
},
"2": {
"name": "coating_systems",
"text": {"0" : "this animation has one text field"}
},
"3": {
"name": "compatability_chart",
"text": {"0" : "this animation has more than one dynamic text field", "1" : "another text field"}
}
}
the name is used by the parent site - here we just need 'text'
In my Adobe CC animation timeline:
var that = this;
var loaded = false;
json = {};
var loadJson = function(url)
{
var queue = new createjs.LoadQueue(true);
queue.on("fileload", onJsonLoaded, that);
queue.on("error", onJsonLoadError, that);
queue.loadFile({id:"json", src:url});
}
var onJsonLoaded = function(e)
{
that.json = e.target.getResult("json");
setText();
}
var onJsonLoadError = function(e)
{
console.log(e);
}
var setText = function()
{
var blocks = that.json;
var numblocks = Object.keys(blocks[id].text).length;
// loop through the text block to assign to the matching count in the animation
for (var i=0; i < numblocks; i++) {
var txtField = eval('that.textField'+i);
txtField.text = blocks[id].text[i];
}
}
//in my case, the "id" and "lang" gets passed from the parent window into the iframe with the animation in a bs carousel - uses data attributes
var $anim_iframe = parent.document.querySelectorAll('.item.active .animation_iframe');
if($anim_iframe.length > 0){
var id = $anim_iframe[0].dataset.id;
var lang = $anim_iframe[0].dataset.lang;
var json_file = '/path/to/lang/'+lang+'.json';
// load json, but don't bother if the animation loops
if(loaded == false){
loadJson(json_file);
}
loaded = true;
}
On your stage you will have dynamic text boxes called textField0, textField1, textField2 etc that match up to the "text" in the json file.
$.ajax({
type: 'GET', // changed from 'tybe'
url: externalurl,
dateType: 'xml',
success: function (xml) {
var Text_Cta1 = $(xml).find("BtnText1")
root.feedTitle.text = titles[0].textContent;
$(xml).find("BtnText1").each(function () (
$item = $(this);
var itme = new Object();
item.title = $item.find("Text_Cta1").text();
feedItems.push('Text_Cta1');
)};
})

HTML5 web audio controls

I have music play example http://www.smartjava.org/examples/webaudio/example3.html
And i need to show html5 audio player (with controls) for this song. How i can do it?
Javascript code from example below:
// create the audio context (chrome only for now)
// create the audio context (chrome only for now)
if (! window.AudioContext) {
if (! window.webkitAudioContext) {
alert('no audiocontext found');
}
window.AudioContext = window.webkitAudioContext;
}
var context = new AudioContext();
var audioBuffer;
var sourceNode;
var analyser;
var javascriptNode;
// get the context from the canvas to draw on
var ctx = $("#canvas").get()[0].getContext("2d");
// create a gradient for the fill. Note the strange
// offset, since the gradient is calculated based on
// the canvas, not the specific element we draw
var gradient = ctx.createLinearGradient(0,0,0,300);
gradient.addColorStop(1,'#000000');
gradient.addColorStop(0.75,'#ff0000');
gradient.addColorStop(0.25,'#ffff00');
gradient.addColorStop(0,'#ffffff');
// load the sound
setupAudioNodes();
loadSound("http://www.audiotreasure.com/mp3/Bengali/04_john/04_john_04.mp3");
function setupAudioNodes() {
// setup a javascript node
javascriptNode = context.createScriptProcessor(2048, 1, 1);
// connect to destination, else it isn't called
javascriptNode.connect(context.destination);
// setup a analyzer
analyser = context.createAnalyser();
analyser.smoothingTimeConstant = 0.3;
analyser.fftSize = 512;
// create a buffer source node
sourceNode = context.createBufferSource();
sourceNode.connect(analyser);
analyser.connect(javascriptNode);
sourceNode.connect(context.destination);
}
// load the specified sound
function loadSound(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
// When loaded decode the data
request.onload = function() {
// decode the data
context.decodeAudioData(request.response, function(buffer) {
// when the audio is decoded play the sound
playSound(buffer);
}, onError);
}
request.send();
}
function playSound(buffer) {
sourceNode.buffer = buffer;
sourceNode.start(0);
}
// log if an error occurs
function onError(e) {
console.log(e);
}
// when the javascript node is called
// we use information from the analyzer node
// to draw the volume
javascriptNode.onaudioprocess = function() {
// get the average for the first channel
var array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(array);
// clear the current state
ctx.clearRect(0, 0, 1000, 325);
// set the fill style
ctx.fillStyle=gradient;
drawSpectrum(array);
}
function drawSpectrum(array) {
for ( var i = 0; i < (array.length); i++ ){
var value = array[i];
ctx.fillRect(i*5,325-value,3,325);
// console.log([i,value])
}
};
I think what you want is to use an audio tag for your source and use createMediaElementSource to pass the audio to webaudio for visualization.
Beware that createMediaElementSource checks for CORS access so you must have appropriate cross-origin access for this to work. (It looks like your audio source doesn't return the appropriate access headers for this to work.)

Accessing audio via function

In Unityscript I'm able to directly access audio data. In the scene, I have a gameobject with a sound file and a script attached to it.
var mySound : AudioClip;
mySound = audio.clip;
var mySoundChannels = mySound.channels;
However, I'm having problems trying to access audio data via a function:
#pragma strict
var mySound : AudioClip;
function Start()
{
mySound = audio.clip;
GetAudio(mySound);
}
function GetAudio(au)
{
print ("Audio: " + (mySound === au)); // true
//var mySoundChannels = mySound.channels; // works
var mySoundChannels = au.channels; // fails
var stereoOrNot = (mySound.channels == 2 ? "stereo" : " mono"); //works
print(stereoOrNot);
}
I thought I could access au.channels, but I'm not sure where I'm going wrong I (apart from wanting to access audio indirectly)
Since you are using a dynamic variable there, I'm not sure if the var mySoundChannels will be typed to an AudioClip or an int. If it is an AudioClip then it will fail because channels are read only. Try it with int mySoundChannels = au.channels;

Getting External Interface to work with swf object, can't figure out what I'm doing wrong

I'm using swf object to embed a swf. I'm trying to user external interface to to call a flash function from JS, but having trouble. I've searched all the docs, read a ton of stuff, and I'm convinced I'm doing it right. Can anyone point out where the problem might be?
var flashvars = {};
var params = {wmode:"opaque", allowscriptaccess:"always" };
var attributes = {id:"MySwf", name:"MySwf"};
swfobject.embedSWF("MySwf.swf", "flashContent", "600", "400", "9.0.0", "swfs/expressInstall.swf", flashvars, params, attributes,function(e){
if(e.success){
_flashRef = e.ref;
testExternalInterface();
}else{
alert("We are sorry, flash is required to view this content.");
}
});
function testExternalInterface(){
var swf = document.getElementById("MySwf");
swf.sendMeTheGoods("TEST TEST");
};
Above is the embed code and js function in my flash I have
if (ExternalInterface.available)
{
trace("adding external interface");
ExternalInterface.addCallback("sendMeTheGoods", sendMeTheGoods);
}
public function sendMeTheGoods(text:String):void
{
trace("setting vars")
trace(text);
txtYouSent.text = text;
}
I'm getting the error Uncaught TypeError: Object # has no method 'sendMeTheGoods'
I've tried both referenceing document.getElementById("MySwf"); and document.getElementById("flashContent"); and I get the error both ways. Any suggestions?
the external interface API is not immediately available, it takes a second for it to be ready. your callback is likely happening before Flash Player has initialized the EI API. try adding a delay in the callback, delaying the invocation of your 'test' function.
var swf = navigator.appName.indexOf("Microsoft") != -1 ? window["MySwf"] : document["MySwf"];