# Play/Pause Toggle for MP3 Player

**URL:** https://forum.kirupa.com/t/play-pause-toggle-for-mp3-player/215262
**Category:** flash
**Created:** [February 5, 2007, 10:04pm UTC](https://forum.kirupa.com/t/play-pause-toggle-for-mp3-player/215262 "2007-02-05T22:04:23Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![heathermorin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/heathermorin/32/3284_2.png) [@heathermorin](https://forum.kirupa.com/u/heathermorin)
#### Post date: [February 5, 2007, 10:04pm UTC](https://forum.kirupa.com/t/play-pause-toggle-for-mp3-player/215262/1 "2007-02-05T22:04:23Z")

</div>

Hello,

If anyone has any suggestions on creating a play/pause effect from the actionscript that I am currently using, it would be greatly appreciated! I already have a play/stop toggle button, but would like to turn it into a play/pause button. (You will probably recognize this from the HOT Flash Prof. 8 book, Beyond The Basics.)

:look: Even though the code for next/previous buttons is listed below, I really only need play/pause toggle functionality…and am at a total loss at how to do this.

The actionscript for each instance of the buttons are as follows:

PLAY:  
on (rollOver) {  
\_root.helpBubble.text = “play music”;  
}

on (rollOut) {  
\_root.helpBubble.text = “”;  
}

on (release) {  
\_root.playMusak();  
nextFrame();  
}

STOP:  
on (rollOver) {  
\_root.helpBubble.text = “stop music”;  
}

on (rollOut) {  
\_root.helpBubble.text = “”;  
}

on (release) {  
\_root.stopMusak();  
prevFrame();  
}

The actionscript that I am using for the overall flash project is as follows:

//----------------\<sound initialization\>-------------------\  
var curTrackNum:Number = 0;  
var bgMusak:Sound;

// autosize some text fields  
this.helpBubble.autoSize = “center”;  
this.trackInfo.autoSize = “left”;

// load the track info vars  
var myMusicLv:LoadVars = new LoadVars();  
myMusicLv.load(“vars/track\_info.txt”);

//----------------\<sound setup\>----------------\

function stopMusak() {  
delete bgMusak;  
}

function playMusak() {  
bgMusak = new Sound();  
bgMusak.onSoundComplete = function() {  
if (curTrackNum == (myMusicLv.totalTracks - 1)) {  
curTrackNum = 0;  
} else {  
curTrackNum ++;  
}  
stopMusak(); /\* change to playMusak(); if want to loop song \*/  
}  
bgMusak.onID3 = function() {  
trackInfo.text = "artist : " + bgMusak.id3.TCOM + " | track : " + bgMusak.id3.TIT2;  
}  
bgMusak.onLoad = function(success) {  
if (!success) {  
trackInfo.text = “Failed to load track.”;  
}  
}

```
bgMusak.loadSound("mp3s/mp3-" + curTrackNum + ".mp3", true);

musakProgBar.onEnterFrame = function() {
    bgMusak.setVolume(musakVolume);
    musakVolume = -musakVolumeMC.musakVolumeSliderMC._y * 2;
    // add and modify percentage text
    musakVolumeMC.volumeTxt.text = musakVolume + "%";
    musakVolumeMC.volumeTxt._y = (-musakVolume/2) - 3;
    musakVolumeMC.volumeTxt._alpha = musakVolume;
    var trackD1Prog:Number = _root.bgMusak.getBytesLoaded() / 1000;
    var trackD1Total:Number = _root.bgMusak.getBytesTotal() / 1000;
    var trackD1Percent:Number = Math.round((trackD1Prog/trackD1Total) * 249);
    var trackD1Duration:Number = Math.round((bgMusak.duration/trackD1Percent) * 249);
    musakProgBar.progMaskContainer.progMask._width = trackD1Percent + 9;
    musakProgBar.musakProg._x = Math.round(_root.bgMusak.position/trackD1Duration * 249);
}

```

}  
//----------------\</sound setup\>----------------\

//----------------\<next track\>-------------------\  
this.nextTrackBtn.onRollOver = function() {  
helpBubble.text = “next track”;  
}

this.nextTrackBtn.onRollOut = function() {  
helpBubble.text = “”;  
}

this.nextTrackBtn.onRelease = function() {  
if (curTrackNum == (myMusicLv.totalTracks - 1)) {  
curTrackNum = 0;  
} else {  
curTrackNum ++;  
}  
stopMusak();  
playMusak();

///  
musakToggle.gotoAndStop(2);  
}

//----------------\</next track\>-------------------\

//----------------\<previous track\>-------------------\

this.prevTrackBtn.onRollOver = function() {  
helpBubble.text = “previous track”;  
}

this.prevTrackBtn.onRollOut = function() {  
helpBubble.text = “”;  
}

this.prevTrackBtn.onRelease = function() {  
if (curTrackNum == 0) {  
curTrackNum = (myMusicLv.totalTracks - 1);  
} else {  
curTrackNum --;  
}  
///  
musakToggle.gotoAndStop(2);  
}

//----------------\</previous track\>-------------------\

//----------------\</sound initialization\>-------------------\

//----------------\<volume control\>-------------------\

// initialize some volume control settings  
this.musakVolumeMC.volumeTxt.autoSize = “left”;  
var musakVolume:Number = 25;  
var speakerClick:Number = 0;  
this.musakVolumeMC.\_visible = false;  
this.musakVolumeMC.musakVolumeSliderMC.\_y = -(musakVolume/2);

// control the visibility of the volume slider  
this.speaker.onRelease = function () {  
if (speakerClick == 0) {  
musakVolumeMC.\_visible = true;  
speakerClick = 1;  
speaker.\_alpha = 50;  
} else {  
musakVolumeMC.\_visible = false;  
speakerClick = 0;  
speaker.\_alpha = 100;  
}  
}

// set what should happen when the volume slider is pressed, released, or released outside  
this.musakVolumeMC.musakVolumeSliderMC.onPress = function() {  
startDrag(this,false,0,-50,0,0);  
///  
}

this.musakVolumeMC.musakVolumeSliderMC.onRelease = function() {  
stopDrag();  
///  
}

this.musakVolumeMC.musakVolumeSliderMC.onReleaseOutside = function() {  
stopDrag();  
///  
}

//----------------\</volume control\>-------------------\
