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;
Related
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
I've been seeing some tools for a browsergame that injects code to a swf file in order to automate some parts of the game.
I've been reading about swf flash format and I'm still don't knowing how that's possible, maybe the program runs the swf file with a custom flash player?
If you could guide me in this I would be very appreciated, this is very interesting.
Just a try:
var actionString:String = "methodAddOne";
var paramString:String = "1";
function methodAddOne(num:String):void{
trace(Number(num)+1);
}
this[actionString](paramString); //trace: 2
For a queue of params:
var actionString2:String="methodAdd";
var paramString2:String="1,2,3,-6";
function methodAdd(nums:String):void{
var params:Array= nums.split(",");
var out=0;
for each(var num:Number in params){
out += num;
}
trace(out);
}
this[actionString2](paramString2);// returns 0
All calculations, core-Methods,... you have to parse. Very complicated...
E.g. try to parse and calculate "1+2+3-6". Its possible of course, but hard to do with other Stuff and math-grammar.
So, the easier way is to provide a String-based Api with all methods, the
user can predefined use with params.
like this:
var stackString:String = "methodAddOne(100); methodAdd(1,2,3);";
function parseFunctionsString(str:String):void
{
//better use regExp at all the following
var f:String = str.substring(0,str.indexOf("("));
var p:String = str.substring(str.indexOf("(") + 1,str.indexOf(")"));
// clean spaces // also better regExp to validate some other user mistakes - just for this test in this way
f = f.replace(" ","");
p = p.replace(" ","");
//trace("** "+f+" ("+p+")");
if (this[f])
{
this[f](p);
}
else
{
trace("unknown function: "+f);
}
str = str.substr(str.indexOf(";") + 1,str.length - str.indexOf(";") + 1);
if (str.length > 2)
{
parseFunctionsString(str);
}
}
parseFunctionsString(stackString);
// trace:
// 101
// 6
As an idea... Greetings André
I have the following code:
thinkGearSocket = new Socket();
var configuration : Object = new Object();
configuration["enableRawOutput"] = true;
configuration["format"] = "Json";
thinkGearSocket.connect("127.0.0.1", 13854);
thinkGearSocket.addEventListener(ProgressEvent.SOCKET_DATA, dataHandler);
thinkGearSocket.writeUTFBytes(JSON.encode(configuration));
It works for flash player 10 but for flash player 11 I get an error saying:
1061: Call to a possibly undefined method encode though a reference with static type flash.net:socket
I had the same error for the decoding with this:
private function dataHandler(e : ProgressEvent){
//read data from the socket
var packetString : String = thinkGearSocket.readUTFBytes(thinkGearSocket.bytesAvailable);
thinkGearSocket.flush();
//split the data into an array
var packets : Array = packetString.split(/\r/);
var data:Object;
//iterate through array elements
for each (var packet:String in packets){
//sometimes the packet is empty
if(packet != "") {
try {
data = JSON.decode(packet);
//trace(packet);
} catch ( jError: JSONParseError) {
// do exception handling here
label1.text = jError.text;
}
But I changed:
data = JSON.decode(packet);
to:
data = JSON.parse(packet);
and now I don't get an error for that part. how do I fix the encoding part for Flash player 11 and AIR 3.0?
You need to use the stringify method instead of encode for Flash 11 or greater.
stringify(value:Object, replacer:* = null, space:* = null):String
You can see more information in the AS3 livedocs for stringify.
I have a variable
var qstAccessCode:String = "default";
and a loader with URLRequest
var qst:XML;
var qstLoader:URLLoader = new URLLoader();
qstLoader.load(new URLRequest("http://dl.dropbox.com/u/44181313/Qaaps/Audio/" + qstAccessCode + ".qst"));
qstLoader.addEventListener(Event.COMPLETE, processQST);
function processQST(e:Event):void {
qst = new XML(e.target.data);
trace("QST loading");
}
I would like to use the value of qstAccessCode to complete the URL (so I can change the URL based on user input - if no input then use "default") but I get an error:
"1120: Access of undefined property qstAccessCode"
Is this to do with scoping? How can I complete the URL? Thanks in advance.
Edit: I haven't been able to get clear on this, so I'm also going to look at generating the complete URL from the user-input function and see if I get the URLRequest to pick it up as a variable. If there are any further comments on the original idea I will be very grateful to read them. Cheers.
Edit: #Moorthy I have qstAccessCode defined like this:
var qatAccessCode:String = "default";
var stageText:StageText = new StageText();
stageText.returnKeyLabel = ReturnKeyLabel.GO;
stageText.stage = this.stage;
stageText.viewPort = new Rectangle(225, 765, 200, 35 );
stageText.addEventListener(Event.CHANGE, onChange);
function onChange(e:Event):void
{
qatAccessCode = stageText.text;
trace(qatAccessCode);
}
It traces keyboard entry when I test movie (Air 3.2 for Android).
qstAccessCode should be defined in the same scope as the URLRequest.
You must defined property qstAccessCode like:
var qstAccessCode:string;
qstAccessCode's value is your url address.
In the following example (yes, I am coding on my timeline while I try to work this out - I know, I know) I am loading an SWF in an HTML page and then directing the SWF to get the query parameters from the current URL. The query parameter will contain the source for the video to play.
This seems straight forward to me but I cannot get myURL = urlVars.videoloc; to work. More specifically, urlVars.videoloc seems to be undefined rather than holding the query parameter from the URL. All other variables are correct; both wholeURL and urlVars are defined.
//Initialize Global Event Listener
player.addEventListener(Event.ADDED_TO_STAGE, getPlay, false, 0, true);
//Function to play the video
function getPlay(e:Event):void {
var wholeURL:String = ExternalInterface.call("window.location.search.toString");
var urlVars:URLVariables = new URLVariables(wholeURL);
var myURL:String = urlVars.videoloc; //<--- Trouble, returning 'undefined'
errorBox.text = "videoloc="+urlVars.videoloc+"\nwholeURL="+wholeURL+"\nurlVars="+urlVars+"\nmyURL="+myURL; //<--- The reason I know it is returning 'undefined'
if (myURL) {
player.load(myURL);
player.play();
}
}
Ideally you should use a debugger to inspect the makeup of your URLVariables object.
If you're unable to do things the easy way, you could do this to trace its contents:
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}
As you can see, you can step through every parameter inside urlVars using a for in loop.
I'm guessing videoLoc is your first parameter? Look at the results of this test of mine:
var address:String = "http://www.google.ca/search?q=test&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a";
var urlVars:URLVariables = new URLVariables(address);
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}
The output of this is:
aq=t
rls=org.mozilla:en-GB:official
client=firefox-a
http://www.google.ca/search?q=test
ie=utf-8
oe=utf-8
See what happened to the q parameter? To fix this, use only the text past the ?
var address:String = "http://www.google.ca/search?q=test&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a";
var urlVars:URLVariables
= new URLVariables(address.substr(address.indexOf('?')+1));
for (var parameter:String in urlVars) {
trace(parameter + "=" + urlVars[parameter]);
}