FORUMS: list search recent posts

Stopping autoplay - MP3 Player on websites

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pete Vran
Stopping autoplay - MP3 Player on websites
on Oct 30, 2012 at 11:04:36 pm

Hi,

Ive been having so many problems trying to stop this autoPlay on my Flash mp3 player and would really appreciate it if someone could let me know where im going wrong.

I have 3 frames and shown the code below:

frame 1
stop();

var myFormat:TextFormat = new TextFormat();
myFormat.color = "0xFFFFFF";

list.setRendererStyle("textFormat", myFormat);

//////////////////////////////////////////////////////////////////////////////////////////////////

// Initialize variables
var trackToPlay:String;
var pausePosition:int = 0;
var songURL:URLRequest;
var isPlaying:Boolean = false;
var i:uint;
// Initialize the XML, place the xml file name, initialize the URLRequest
// put URLRequest into a new URLLoader, and add event listener on
// myLoader listening for when the XML loading is complete
var myXML:XML = new XML();
var XML_URL:String = "FREE.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

// Create the xmlLoaded function. What happens when the XML file is fully read
function xmlLoaded(event:Event):void {

// Place the xml data into the myXML object
myXML = XML(myLoader.data);
// Access song 1 in the XML file to start the player
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
songURL = new URLRequest("FREE/" + firstSong + ".mp3");
//status_txt.text = "1. "+firstSong +" - "+firstArtist;
// Run the "for each" loop to iterate through all of the song items listed in the external XML file
for each (var Song:XML in myXML..Song) {

i++; // Increment the song counter by one
// Access the value of the "itemColor" node in our external XML file
var songTitle:String = Song.songTitle.toString();
// Access the value of the "itemLabel" node in our external XML file
var songArtist:String = Song.songArtist.toString();
// Adds each song into the list component through this loop
list.addItem( { label: i+". "+songTitle+" - "+songArtist, songString: songTitle, Artist: songArtist, songNum: i } );

}
var myArray = new Array (0,0);
list.selectedIndices = myArray; // This highlights song 1 by default
gotoAndStop(3);

}



frame 2
// This is where and when the song switching takes place when a list cell is clicked
songURL = new URLRequest("FREE/" + trackToPlay + ".mp3");



frame 3
stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition); // Start playing
// Set "isPalying" to true now that song is playing
isPlaying = true;
// Make play button show the pause symbol on it
playBtn.gotoAndStop(2);
// Playlist item click listener
list.addEventListener(Event.CHANGE, itemClick);
// Playlist item click function
function itemClick (event:Event):void {
channel.stop(); // stop play
pausePosition = 0;
//status_txt.text = event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songString;
gotoAndPlay(2);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stop Button Function
function stopPlayer (event:MouseEvent):void {
channel.stop();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Play & Pause Function //////////////////////////////////////////////////////
function playPause(event:MouseEvent):void {

if (isPlaying == true) {

pausePosition = channel.position;
channel.stop();
playBtn.gotoAndStop(1);
isPlaying = false;

} else {

channel = snd.play(pausePosition);
playBtn.gotoAndStop(2);
isPlaying = true;
}

}
////////////////////////////////////////////////////////////////////////////////////
// Play Next Button Function //////////////////////////////////////////////////////
function playNext(event:MouseEvent):void {
newTrack();

}
////////////////////////////////////////////////////////////////////////////////////
// Play Previous Button Function //////////////////////////////////////////////////////
function previousSound(event:MouseEvent):void {

// set some variables here
var prevNum:uint = list.selectedItem.songNum - 2;
var selectPrevSong = new Array (prevNum,prevNum); // array for cell select
var indexMinus1:uint = i -1; // This takes the index and subtracts 1 from it in order to select the correct song
var lastSongInList = new Array (indexMinus1,indexMinus1); // array for cell select of very last song in list

if (list.selectedItem.songNum == 1) {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

} else {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

}
pausePosition = 0;
}
// Button Listeners ///////////////////////////////////////////////////////////////////////
stop_btn.addEventListener(MouseEvent.CLICK, stopPlayer);
playBtn.addEventListener(MouseEvent.CLICK, playPause);
previousBtn.addEventListener(MouseEvent.CLICK, previousSound);
nextBtn.addEventListener(MouseEvent.CLICK, playNext);

// Place track amount and current track # into our text field
songCount_txt.text = "Now Playing Song " + list.selectedItem.songNum + " of " + i;

// Event Listener for sound complete when any song finishes
channel.addEventListener(Event.SOUND_COMPLETE, onCompletePlayback);
// Function inSoundComplete
function onCompletePlayback (event:Event):void {
newTrack();
}
// New track play function
function newTrack():void {
if (list.selectedItem.songNum == i) { // if songNum == total track amount
channel.stop(); // stop the player
var selectFirst = new Array (0,0); // array for cell select
list.selectedIndices = selectFirst; // This selects song 1
list.scrollToIndex(0);
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
} else {
channel.stop(); // stop the player
var sn:uint = list.selectedItem.songNum; // var that has value of current list songNum
var selectNext = new Array (sn,sn); // array for cell select
list.selectedIndices = selectNext; // This selects next song in the list component
list.scrollToIndex(sn);
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
}
// Always set pausePosition back to 0 here
pausePosition = 0;
} /// Close newTrack function
////////////////////////////////////////////////////////////////////////////////////


/////////////// Track Scrubber and Ghost Scrub Knob /////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------ Along with the follower clip inside the trackScrubber
var isDragging:Boolean;
trackScrubber.ghostKnob.visible = false;
// Set Bounds
var scrubberBounds = new Rectangle(0,trackScrubber.ghostKnob.y,trackScrubber.scrubberRect.width,0);
trackScrubber.addEventListener(MouseEvent.MOUSE_DOWN, dragScrub);
stage.addEventListener(MouseEvent.MOUSE_UP, dropScrub);

// Drag scrubber
function dragScrub(evt:Event):void {
trackScrubber.ghostKnob.startDrag(true,scrubberBounds);
trackScrubber.ghostKnob.visible = true;
isDragging = true;
}
// Drop scrubber
function dropScrub(evt:Event):void {

if (isPlaying == true && isDragging == true) {

stopDrag();
// Calculate full time of this track
var fullTime:int = Math.floor(snd.length / 1000);
// Claim a var for the position the song is where we release the scrubber after dragging
var newPos:Number = fullTime / 100 * Math.floor(trackScrubber.ghostKnob.x * 1000);
// Important to set new pause position here
trackToPlay = list.selectedItem.songString; // Define track to resume
pausePosition = newPos / 2;
channel.stop();
gotoAndPlay(2);
//channel = snd.play(newPos);
isPlaying = true;
isDragging = false;

} else { // if not playing
isDragging = false;
trackScrubber.ghostKnob.visible = false;
//pausePosition = fullTime / 100 * Math.floor(trackScrubber.tBarKnob.x * 1000);

}

}
/////////////// End Track Scrubber and Seek Bar //////////////////////////////////////////////////////////////////////////////////////////////


// Set up the onEnterFrame Event for EQ and other various things we may add later on
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {

// ANIMATED EQ BARS CODE
/* eqBarLeft1.gotoAndStop (Math.round(channel.leftPeak * 10) ); // 10 is the amount of frames in our EQbar clips
eqBarRight1.gotoAndStop (Math.round(channel.rightPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft2.gotoAndStop (Math.round(channel.leftPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarRight2.gotoAndStop (Math.round(channel.rightPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft3.gotoAndStop (Math.round(channel.leftPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarRight3.gotoAndStop (Math.round(channel.rightPeak * 10) ); // 10 is the amount of frames in our EQbar clips
*/
// Set and change volume if they drag
var volumeLevel = channel.soundTransform;
var newLevel:Number = (volumeSlider.knob.x) / -100;
volumeLevel.volume = newLevel;
channel.soundTransform = volumeLevel;
volumeSlider.volumeLightBar.width = volumeSlider.knob.x;

// Get full time of the song
var tallytime = (snd.length/1000);
var totalmins:Number = Math.floor(tallytime /60);
var totalsecs = Math.floor (tallytime) % 60;
if (totalsecs < 10){
totalsecs = "0" + totalsecs;
}
displayFullTime.text = ( " " + totalmins+ ":" + totalsecs);
// End get Full time
// Get playing time of the song
var totalSeconds:Number = channel.position/1000;
var minutes:Number = Math.floor(totalSeconds /60);
var seconds = Math.floor (totalSeconds) % 60;
if (seconds < 10){
seconds = "0" + seconds;
}
displayTime.text = ( " " + minutes+ ":" + seconds);
// End get playing time

/// progress bar code...
var estimatedLength:int = Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal));
var playbackPercent:uint = 100 * (channel.position / estimatedLength );
// I want my position bar to be 200 pixels wide on completion so I multiply the percentage x 2
trackScrubber.positionBar.width = playbackPercent * 2;
trackScrubber.follower.x = trackScrubber.positionBar.width;
// make the loaded progress bar that lives under the playhead progress bar grow dynamically
var loadedPercent:uint = 100 * (snd.bytesLoaded / snd.bytesTotal);
trackScrubber.loadedProgressBar.width = loadedPercent * 2;
}



Thanks in advance.

Pete


Return to posts index

Sam Mattern
Re: Stopping autoplay - MP3 Player on websites
on Oct 31, 2012 at 8:35:49 pm

Can you expound on your problem? Is the MP3 autoplaying, but you don't want it to?

-Sam


Return to posts index

Pete Vran
Re: Stopping autoplay - MP3 Player on websites
on Oct 31, 2012 at 10:50:46 pm

Sorry, yes its currently auto playing but I want to disable that. I need the music to start only when the play button is clicked.

Thanks for the reply,
Pete


Return to posts index


Sam Mattern
Re: Stopping autoplay - MP3 Player on websites
on Nov 1, 2012 at 2:04:22 pm

Without doing a more in-depth analysis of your code, it's playing because you're telling it to play. For instance, right after you load the file, you set it to play:

frame 3
stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
<b>channel = snd.play(pausePosition); // Start playing</b>


Trying moving that code to a place that's activated by your play button. Or you could add a channel.stop(); right after the channel = snd.play(pausePosition);. That way everything is still initialized in place.

-Sam


Return to posts index

Pete Vran
Re: Stopping autoplay - MP3 Player on websites
on Nov 1, 2012 at 10:37:27 pm

I tried the channel.stop(); this does stop auto play however because I have more than one mp3 in the player whenever the track is skipped to the next, the user needs to press play everytime.

the play button already has the code : channel = snd.play(pausePosition); so I removed from the top part of the code and this threw an error.

if you have any more ideas on this i'd appreciate it :) I really dont want to start again, this took me hours!


Thanks
Pete


Return to posts index

Sam Mattern
Re: Stopping autoplay - MP3 Player on websites
on Nov 2, 2012 at 1:02:12 pm

I would use the "isPlaying" boolean variable to control this. Add a check after you load a song to see if "isPlaying" is true. If it is, have it play. If it is not, have it not play. This code will also prevent the first song from playing. Going back to your original code, remove the "isPlaying = true;" in the beginning and check for the variable's state instead. This tells the program to only start playing if one was already playing (or if the play button is pressed, which you'll have to modify that code to set the isPlaying variable to true after your channel.play(); call):

stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
<b>if( isPlaying == true ){
channel = snd.play(pausePosition); // Start playing
playBtn.gotoAndStop(2);
}
</b>
// Playlist item click listener
list.addEventListener(Event.CHANGE, itemClick);
// Playlist item click function
function itemClick (event:Event):void {
channel.stop(); // stop play
<b>isPlaying == false;</b>
pausePosition = 0;
//status_txt.text = event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songString;
gotoAndPlay(2);

}


You just want to be careful that every time you do a "channel.stop()", you set "isPlaying" to false and every time you do a "channel.play()" you set "isPlaying" to true. If you miss one, it'll start acting funny.

-Sam


Return to posts index


Pete Vran
Re: Stopping autoplay - MP3 Player on websites
on Nov 4, 2012 at 10:39:04 pm

Thats a good idea. I tried using the isPlaying to control this but im getting a syntax error:

1084: Syntax Error: Expecting right brace before semi colon.

its pointing me to: channel = snd.play(pausePosition);

ive tried moving the right brace to different places but still not working.


Return to posts index

Sam Mattern
Re: Stopping autoplay - MP3 Player on websites
on Nov 5, 2012 at 12:17:06 am

Can you post your code again?

-Sam


Return to posts index

Pete Vran
Re: Stopping autoplay - MP3 Player on websites
on Nov 5, 2012 at 3:45:57 pm

Thanks - Code seperated in 3 frames:

stop();

var myFormat:TextFormat = new TextFormat();
myFormat.color = "0xFFFFFF";

list.setRendererStyle("textFormat", myFormat);

//////////////////////////////////////////////////////////////////////////////////////////////////

// Initialize variables
var trackToPlay:String;
var pausePosition:int = 0;
var songURL:URLRequest;
var isPlaying:Boolean = false;
var i:uint;
// Initialize the XML, place the xml file name, initialize the URLRequest
// put URLRequest into a new URLLoader, and add event listener on
// myLoader listening for when the XML loading is complete
var myXML:XML = new XML();
var XML_URL:String = "FREE.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

// Create the xmlLoaded function. What happens when the XML file is fully read
function xmlLoaded(event:Event):void {

// Place the xml data into the myXML object
myXML = XML(myLoader.data);
// Access song 1 in the XML file to start the player
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
songURL = new URLRequest("FREE/" + firstSong + ".mp3");
//status_txt.text = "1. "+firstSong +" - "+firstArtist;
// Run the "for each" loop to iterate through all of the song items listed in the external XML file
for each (var Song:XML in myXML..Song) {

i++; // Increment the song counter by one
// Access the value of the "itemColor" node in our external XML file
var songTitle:String = Song.songTitle.toString();
// Access the value of the "itemLabel" node in our external XML file
var songArtist:String = Song.songArtist.toString();
// Adds each song into the list component through this loop
list.addItem( { label: i+". "+songTitle+" - "+songArtist, songString: songTitle, Artist: songArtist, songNum: i } );

}
var myArray = new Array (0,0);
list.selectedIndices = myArray; // This highlights song 1 by default
gotoAndStop(3);

}


// This is where and when the song switching takes place when a list cell is clicked
songURL = new URLRequest("FREE/" + trackToPlay + ".mp3");


stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition); // Start playing
// Set "isPalying" to true now that song is playing
isPlaying = true;
// Make play button show the pause symbol on it
playBtn.gotoAndStop(2);
// Playlist item click listener
list.addEventListener(Event.CHANGE, itemClick);
// Playlist item click function
function itemClick (event:Event):void {
channel.stop(); // stop play
pausePosition = 0;
//status_txt.text = event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songString;
gotoAndPlay(2);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stop Button Function
function stopPlayer (event:MouseEvent):void {
channel.stop();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Play & Pause Function //////////////////////////////////////////////////////
function playPause(event:MouseEvent):void {

if (isPlaying == true) {

pausePosition = channel.position;
channel.stop();
playBtn.gotoAndStop(1);
isPlaying = false;

} else {

channel = snd.play(pausePosition);
playBtn.gotoAndStop(2);
isPlaying = true;
}

}
////////////////////////////////////////////////////////////////////////////////////
// Play Next Button Function //////////////////////////////////////////////////////
function playNext(event:MouseEvent):void {
newTrack();

}
////////////////////////////////////////////////////////////////////////////////////
// Play Previous Button Function //////////////////////////////////////////////////////
function previousSound(event:MouseEvent):void {

// set some variables here
var prevNum:uint = list.selectedItem.songNum - 2;
var selectPrevSong = new Array (prevNum,prevNum); // array for cell select
var indexMinus1:uint = i -1; // This takes the index and subtracts 1 from it in order to select the correct song
var lastSongInList = new Array (indexMinus1,indexMinus1); // array for cell select of very last song in list

if (list.selectedItem.songNum == 1) {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

} else {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

}
pausePosition = 0;
}
// Button Listeners ///////////////////////////////////////////////////////////////////////
stop_btn.addEventListener(MouseEvent.CLICK, stopPlayer);
playBtn.addEventListener(MouseEvent.CLICK, playPause);
previousBtn.addEventListener(MouseEvent.CLICK, previousSound);
nextBtn.addEventListener(MouseEvent.CLICK, playNext);

// Place track amount and current track # into our text field
songCount_txt.text = "Now Playing Song " + list.selectedItem.songNum + " of " + i;

// Event Listener for sound complete when any song finishes
channel.addEventListener(Event.SOUND_COMPLETE, onCompletePlayback);
// Function inSoundComplete
function onCompletePlayback (event:Event):void {
newTrack();
}
// New track play function
function newTrack():void {
if (list.selectedItem.songNum == i) { // if songNum == total track amount
channel.stop(); // stop the player
var selectFirst = new Array (0,0); // array for cell select
list.selectedIndices = selectFirst; // This selects song 1
list.scrollToIndex(0);
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
} else {
channel.stop(); // stop the player
var sn:uint = list.selectedItem.songNum; // var that has value of current list songNum
var selectNext = new Array (sn,sn); // array for cell select
list.selectedIndices = selectNext; // This selects next song in the list component
list.scrollToIndex(sn);
trackToPlay = list.selectedItem.songString; // Define New track to play
//status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
}
// Always set pausePosition back to 0 here
pausePosition = 0;
} /// Close newTrack function
////////////////////////////////////////////////////////////////////////////////////


/////////////// Track Scrubber and Ghost Scrub Knob /////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------ Along with the follower clip inside the trackScrubber
var isDragging:Boolean;
trackScrubber.ghostKnob.visible = false;
// Set Bounds
var scrubberBounds = new Rectangle(0,trackScrubber.ghostKnob.y,trackScrubber.scrubberRect.width,0);
trackScrubber.addEventListener(MouseEvent.MOUSE_DOWN, dragScrub);
stage.addEventListener(MouseEvent.MOUSE_UP, dropScrub);

// Drag scrubber
function dragScrub(evt:Event):void {
trackScrubber.ghostKnob.startDrag(true,scrubberBounds);
trackScrubber.ghostKnob.visible = true;
isDragging = true;
}
// Drop scrubber
function dropScrub(evt:Event):void {

if (isPlaying == true && isDragging == true) {

stopDrag();
// Calculate full time of this track
var fullTime:int = Math.floor(snd.length / 1000);
// Claim a var for the position the song is where we release the scrubber after dragging
var newPos:Number = fullTime / 100 * Math.floor(trackScrubber.ghostKnob.x * 1000);
// Important to set new pause position here
trackToPlay = list.selectedItem.songString; // Define track to resume
pausePosition = newPos / 2;
channel.stop();
gotoAndPlay(2);
//channel = snd.play(newPos);
isPlaying = true;
isDragging = false;

} else { // if not playing
isDragging = false;
trackScrubber.ghostKnob.visible = false;
//pausePosition = fullTime / 100 * Math.floor(trackScrubber.tBarKnob.x * 1000);

}

}
/////////////// End Track Scrubber and Seek Bar //////////////////////////////////////////////////////////////////////////////////////////////


// Set up the onEnterFrame Event for EQ and other various things we may add later on
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {

// ANIMATED EQ BARS CODE
/* eqBarLeft1.gotoAndStop (Math.round(channel.leftPeak * 10) ); // 10 is the amount of frames in our EQbar clips
eqBarRight1.gotoAndStop (Math.round(channel.rightPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft2.gotoAndStop (Math.round(channel.leftPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarRight2.gotoAndStop (Math.round(channel.rightPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft3.gotoAndStop (Math.round(channel.leftPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarRight3.gotoAndStop (Math.round(channel.rightPeak * 10) ); // 10 is the amount of frames in our EQbar clips
*/
// Set and change volume if they drag
var volumeLevel = channel.soundTransform;
var newLevel:Number = (volumeSlider.knob.x) / -100;
volumeLevel.volume = newLevel;
channel.soundTransform = volumeLevel;
volumeSlider.volumeLightBar.width = volumeSlider.knob.x;

// Get full time of the song
var tallytime = (snd.length/1000);
var totalmins:Number = Math.floor(tallytime /60);
var totalsecs = Math.floor (tallytime) % 60;
if (totalsecs < 10){
totalsecs = "0" + totalsecs;
}
displayFullTime.text = ( " " + totalmins+ ":" + totalsecs);
// End get Full time
// Get playing time of the song
var totalSeconds:Number = channel.position/1000;
var minutes:Number = Math.floor(totalSeconds /60);
var seconds = Math.floor (totalSeconds) % 60;
if (seconds < 10){
seconds = "0" + seconds;
}
displayTime.text = ( " " + minutes+ ":" + seconds);
// End get playing time

/// progress bar code...
var estimatedLength:int = Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal));
var playbackPercent:uint = 100 * (channel.position / estimatedLength );
// I want my position bar to be 200 pixels wide on completion so I multiply the percentage x 2
trackScrubber.positionBar.width = playbackPercent * 2;
trackScrubber.follower.x = trackScrubber.positionBar.width;
// make the loaded progress bar that lives under the playhead progress bar grow dynamically
var loadedPercent:uint = 100 * (snd.bytesLoaded / snd.bytesTotal);
trackScrubber.loadedProgressBar.width = loadedPercent * 2;
}


Return to posts index


Sam Mattern
Re: Stopping autoplay - MP3 Player on websites
on Nov 5, 2012 at 4:04:29 pm

One thing I'm wondering is if "pausePosition" is out of scope. First try commenting out the line giving you fits and put a trace for "pausePosition":

stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
<b>
trace("pausePosition = "+pausePosition);
//channel = snd.play(pausePosition); // Start playing</b>

// Set "isPalying" to true now that song is playing
isPlaying = true;
// Make play button show the pause symbol on it
playBtn.gotoAndStop(2);


If you don't get an error, you know it's a problem with that call. I've looked through the code, and it seems all opening braces have closing braces. Check to see what your "pausePosition" is returning. If it's NaN or something, the variable is out of scope (defined on frame 1). If it is returning something, please let me know what it is.

-Sam


Return to posts index

Pete Vran
Re: Stopping autoplay - MP3 Player on websites
on Nov 8, 2012 at 9:10:20 pm

Sorry im not the best at this as you can probably tell! I changed the code and got the following error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.


cheers


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]