So, here's the skinny:
Running popcorn.js on a youtube video and separate audio loops. Each one is a track like 'video' and 'audio1' etc.
I have user interaction over a sockets that is sending commands to the window as strings like "Play_audio1". This string is then parsed using split.
so we get:
var messageArray = message.split("_");
thus messageArray[0] is my command, and messageArray[1] is what track to do it to.
THE PROBLEM
I'm trying to execute the code to select the track using window, and run the popcorn function play() on it, but it aint working. Shoots back undefined.
case 'Play':
window[messageArray[1]][play]();
break;
Where's my mistake here?
eval() works, but I heard it was the devil.
EDIT:
To help add to this, I'll include a popcorn.js track code:
var audio1 = Popcorn.smart( "#audio1", "audiofile1.wav",{
frameAnimation: true
});
and in your html you have
<audio id="audio1"></audio>
popcorn.js fills it with your selected file, and to play, you normally just use
audio1.play();
I think that's because you're using messageArray[1] as an index for window. Maybe you should try to create a variable with that value first. Then use it inside window.
var audioFile = messageArray[1];