# Help with this audio player code?

**URL:** <https://forum.kirupa.com/t/help-with-this-audio-player-code/74832>\
**Category:** flash\
**Created:** [January 3, 2005, 5:13am UTC](https://forum.kirupa.com/t/help-with-this-audio-player-code/74832 "2005-01-03T05:13:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesO](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@JamesO](https://forum.kirupa.com/u/JamesO)\
**Post date:** [January 3, 2005, 5:13am UTC](https://forum.kirupa.com/t/help-with-this-audio-player-code/74832/1 "2005-01-03T05:13:52Z")

</div>

Hi everyone. I made this player to be very extensible. The user just needs to upload his mp3’s and a txt. When I debug there aren’t any problems, but the sound doesn’t come out.

The text file needs to be called total\_tracks.txt, and the text inside that file is “totalTracks=2”, where the 2 would be whatever number of files you have in your music directory. Instance names are playMusic, pauseMusic, nextTrack, and prevTrack. mp3 names are mp3-0, mp3-1, mp3-2, etc. and are stored in a directory/folder named “music.”

This is my AS.

var musicFolderName:String = “music”;  
var curTrackNum:Number = 0;  
var curPlaybackPos:Number;  
var mySound:Sound;  
var trackInfoArray:Array;  
var trackInfoTracker:Number = 0;  
var infoChangerInterv:Number;

this.trackInfo.autoSize = “center”; // this can also be “left” or “right” depending on where you want the text to align. \

function playMusicFunc() {  
var mySound:Sound = new Sound();  
mySound.onSoundComplete = function() {  
if (curTrackNum == (myLV.totalTracks - 1)) {  
curTrackNum = 0;  
playMusicFunc();  
} else {  
curTrackNum++;  
playMusicFunc();  
}  
}

mySound.loadSound((musicFolderName + “mp3-” + curTrackNum + “.mp3”), true);  
disablePlay();

mySound.onID3 = function() {  
trackInfoArray = new Array();  
trackInfoArray[0] = "artist : " + mySound.id3TCOM;  
trackInfoArray[1] = "track : " + mySound.id3.TIT2;  
trackInfoArray[2] = "track " + (curTrackNum + 1) + " of " + myLV.totalTracks;

```
clearInterval(infoChangerInterv);
infoChangerInterv = setInterval(infoChanger, 5000); // this controls how often the ID3 info changes in milliseconds. So this changes the ID3 every five seconds. Adjust this to fit your taste) \\ 
infoChanger();

```

}

if (curTrackNum == (myLV.totalTracks - 1)) {  
nextTrack.enabled = false;  
nextTrack.\_alpha = 50; // adjust alpha value to your taste \  
} else {  
nextTrack.enabled = true;  
nextTrack.\_alpha = 100; // adjust alpha value to your taste \  
}

if (curTrackNum == 0) {  
prevTrack.enabled = false;  
prevTrack.\_alpha = 50; // adjust alpha value to your taste \  
} else {  
prevTrack.enabled = true;  
prevTrack.\_alpha = 100; // adjust alpha value to your taste \  
}  
}

function infoChanger() {  
trackInfo.text = trackInfoArray[trackInfoTracker];  
if (trackInfoTracker == (trackInfoArray.length - 1)) {  
trackInfoTracker=0;  
} else {  
trackInfoTracker++;  
}  
}

function restartTrackInfo() {  
infoChangerInterv = setInterval(infoChanger, 5000); // this controls how often the ID3 info changes in milliseconds. So this changes the ID3 every five seconds. Adjust this to fit your taste \  
infoChanger();  
}

var myLV:LoadVars = new LoadVars();  
myLV.load(“total\_tracks.txt”);  
myLV.onLoad = function(success) {  
if (success) {  
playMusicFunc();  
}  
}

// ------------- play/pause -------------- \

this.pauseMusic.onRelease = function() {  
curPlaybackPos = mySound.position;  
mySound.stop();  
disablePause();  
clearInterval(infoChangerInterv);  
}

this.playMusic.onRelease = function() {  
mySound.start((curPlaybackPos/1000), 9999);  
disablePlay();  
restartTrackInfo()  
}

function disablePlay() {  
playMusic.enabled = false;  
playMusic.\_alpha = 50; // adjust alpha value to your taste \  
pauseMusic.enabled = true;  
pauseMusic.\_alpha = 100; // adjust alpha value to your taste \  
trackInfo.\_alpha = 100; // adjust alpha value to your taste \  
}

function disablePause() {  
playMusic.enabled = true;  
playMusic.\_alpha = 100; // adjust alpha value to your taste \  
pauseMusic.enabled = false;  
pauseMusic.\_alpha = 50; // adjust alpha value to your taste \  
trackInfo.\_alpha = 50; // adjust alpha value to your taste \  
}

// ------------- /play/pause -------------- \

// ------------- next track/previous track -------------- \  
this.nextTrack.onRelease = function() {  
if (curTrackNum \< (myLV.totalTracks - 1)) {  
curTrackNum++;  
playMusicFunc();  
}  
}

this.prevTrack.onRelease = function() {  
if (curTrackNum \> 0) {  
curTrackNum–;  
playMusicFunc();  
}  
}

// ------------- /next track/previous track -------------- \
