I have this big script. It works great.
I know the phrase “if it ain’t broke don’t fix it” but I want to make sure that the code layout is as efficient as possible without changing the formulated output (something I’m not very good at).
Does anyone see any areas in my code that can be altered to operate more efficiently without any shift in functional behavior?
Just wondering in case it’s possible to trim the code down.
My script …
[CODE]var visual;
var bandwidth;
var live;
var so;
var audio;
var playing;
function PlayTrack(track) {
if (!video.closed && video.location) visual = video.visual;
else visual = ‘closed’;
if (track != ‘mute’ && track != ‘false’ && track != ‘webcast’) {
if (bandwidth == undefined) bandwidth = flash.GetVariable(‘bandwidth’);
if (track == ‘true’) {
if (audio != ‘off’ && playing != ‘mp3’ && visual != ‘video’) track = ‘5’;
else track = ‘ignore’;
live = ‘false’;
}
if (track != ‘ignore’) {
so = new SWFObject(‘audio/’ + bandwidth + ‘/audio_player.swf’, ‘audio_player’, ‘0’, ‘0’, ‘9’, ‘#000000’, ‘low’);
so.addParam(‘scale’, ‘noscale’);
so.addParam(‘swliveconnect’, ‘false’);
so.addParam(‘allowscriptaccess’, ‘never’);
so.addParam(‘menu’, ‘false’);
so.addVariable(‘wimpyApp’, ‘audio/’ + bandwidth + ‘/audio_config.php’);
so.addVariable(‘wimpySkin’, ‘audio/’ + bandwidth + ‘/audio_skin.xml’);
so.addVariable(‘wW’, ‘0’);
so.addVariable(‘wH’, ‘0’);
so.addVariable(‘theVolume’, ‘100’);
so.addVariable(‘bufferAudio’, ‘0’);
so.addVariable(‘startPlayingOnload’, ‘yes’);
so.addVariable(‘randomPlayback’, ‘yes’);
so.addVariable(‘serveMP3’, ‘yes’);
if (track != ‘random’) so.addVariable(‘startOnTrack’, track);
else so.addVariable(‘defaultPlayRandom’, ‘yes’);
if (live == ‘true’) so.addVariable(‘autoAdvance’, ‘no’);
audio = ‘on’;
playing = ‘mp3’;
if (visual != ‘closed’) video.close();
so.write(‘audio_wrapper’);
flash.audioOn();
}
else if (playing != ‘mp3’) {
if (playing != ‘stopped’) {
document.getElementById(‘audio_wrapper’).innerHTML = ‘*’;
playing = ‘stopped’;
}
flash.audioOff();
}
}
else if (track == ‘mute’ || track == ‘false’) {
if (playing != ‘stopped’) {
document.getElementById(‘audio_wrapper’).innerHTML = ‘*’;
if (track == ‘false’) audio = ‘off’;
playing = ‘stopped’;
}
flash.audioOff();
}
else if (track == ‘webcast’) {
live = ‘true’;
if (visual != ‘closed’) video.ShowWebcast();
else {
so = new SWFObject(‘http://player.stickam.com/stickamPlayer/173556016-310’, ‘audio_player’, ‘0’, ‘0’, ‘9’, ‘#000000’, ‘low’);
so.addParam(‘scale’, ‘noscale’);
so.addParam(‘swliveconnect’, ‘false’);
so.addParam(‘allowscriptaccess’, ‘never’);
so.addParam(‘menu’, ‘false’);
playing = ‘webcast’;
so.write(‘audio_wrapper’);
}
}
active = ‘false’;
}