Skip to main content
Known Participant
May 2, 2013
Question

How do you make an automatic seekbar/scrubber?

  • May 2, 2013
  • 1 reply
  • 638 views

Hi there,

              I have made my own functional mp3 media player in actionscript 3.0 where I can play a song, and I have a seekbar/scrubber which I can scrub through the song.
The question I am now asking as I have searched many forums and on google, is how I can make the seekbar/scrubber move with the song automatically.

Any help is appreciated, Thanks Casey

// Variable List

var my_songs:XMLList; // create variable for reference to XML nodes in playlist

var my_total:Number; // create variable to hold number of songs in playlist

var my_sound:Sound; // create variable to hold sound object

var my_channel:SoundChannel; // create variable to hold sound channel object

var dragging:Boolean = false; // boolean to detect state of vol slider drag

var isDragging:Boolean = true; // boolean to detect state of scrubber/seekbar

var rectangle:Rectangle = new Rectangle(0,-75,0,75); // place vol slider objects

var rectangle2:Rectangle = new Rectangle(0,0,685.5,0);

var current_song:Number = 0; // current song counter (first position in the array)

var song_position:Number; // song position

var song_paused:Boolean; // is song paused? true or false?

var myXMLLoader:URLLoader = new URLLoader(); // variable to hold the URLLoader class

var pausePosition:int=0;

// seekbar ui controls setup

seekBar_mc.sliderSeek_mc.buttonMode = true;

seekBar_mc.sliderSeek_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt2); // call drag function

stage.addEventListener(MouseEvent.MOUSE_UP, dropIt2); // call drop function

// function dragIT2

// dragging slider

function dragIt2(e:Event):void

{

          e.currentTarget.startDrag(true, rectangle2); // seek bar of rectangle constrained

          isDragging = true; // flip the boolean value to true (dragging)

          seekBar_mc.sliderSeek_mc.addEventListener(Event.ENTER_FRAME, onPlayProgress); // call the onPlayProgress function

}

// function dropIT2

// dropping slider

function dropIt2(e:Event):void

{

          if (song_paused == false)

          {

                    if (isDragging == true)

                    {

                              stopDrag();

                              var fullTime:int = Math.floor(my_sound.length/1000);

                              //my_sound.length:int = Math.ceil(my_sound.length /(my_sound.bytesLoaded / my_sound.bytesTotal));

                              var newPos:Number = fullTime/685.5 * Math.floor(seekBar_mc.sliderSeek_mc.x * 1000);

                              pausePosition = newPos/2;

                              my_channel.stop();

                              gotoAndPlay(2);

                              my_channel = my_sound.play(newPos);

                              song_paused = false;

                              isDragging = false;

                    }

          }else

          {

                    isDragging = false;

                    seekBar_mc.sliderSeek_mc.stopDrag();

                    //seekBar_mc.sliderSeek_mc.visible = false;

                    //pausePosition = _totalTime / 100 * Math.floor(seekBar_mc.sliderSeek.mc.x * 1000);

 

 

          }

}

// onPlayProgress

function onPlayProgress(event:Event):void

{

          var seekbar:Number = seekBar_mc.sliderSeek_mc.x / 100; 

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 2, 2013

create a loop (eg, enterframe) and repeatedly use your soundchannel's position property to update your play indicator.