Accesing 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) Any ideas? Thank you.

Answers


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;


Need Your Help

load form using jquery ajax and resubmit that form without page refresh

ajax forms loaded

i want to submit form which loaded via jquery without refreshing the whole page.