Duration And Position Of Sound Object
Hi, I have a MP3 player which progressively downloads MP3s from my server. I can display the IDtags for song name and track info just fine. But I am having trouble displaying the current time and total time of the current mp3 in my dynamic text fields: 'posTime' and 'songInfo'.
Can anybody help? Thanks, Henrik
ActionScript Code: function playMusic() { myMusic = new Sound(); //MP3 Timecode Code: posMins = Math.floor(myMusic.position/1000/60); posSecs = Math.round(myMusic.position/1000%60); //Single Digit Check Code: if(posSecs<10){ posSecs = "0"+Math.round(myMusic.position/1000%60); } //Display MP3 Time to user: posTime.text = " "+posMins+":"+posSecs+" "; songInfo.text = ""+posTime+"" myMusic.onSoundComplete = function() { if (curTrackNum == (myMusicLv.totalTracks) -1) { curTrackNum = 0; } else { curTrackNum++; } playMusic(); }; myMusic.onID3 = function() { trackInfo.text = myMusic.id3.TIT2; trackCount.text = myMusic.id3.TRCK; }; myMusic.onLoad = function(success) { if (!success) { trackInfo.text = "Failed to load track."; } } myMusic.loadSound("mp3s/mp3-"+curTrackNum+".mp3", true);
Ultrashock Forums > Flash > ActionScript
Posted on: 2006-03-15
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Display Duration And Position Of Sound Object
Hi, I have a MP3 player which progressively downloads MP3s from my server. I can display the IDtags for song name and track info just fine. But I am having trouble displaying the current time and total time of the current mp3 in my dynamic text fields: 'posTime' and 'songInfo'.
Can anybody help? Thanks, Henrik
function playMusic() {
myMusic = new Sound();
//MP3 Timecode Code:
posMins = Math.floor(myMusic.position/1000/60);
posSecs = Math.round(myMusic.position/1000%60);
//Single Digit Check Code:
if(posSecs<10){
posSecs = "0"+Math.round(myMusic.position/1000%60);
}
//Display MP3 Time to user:
posTime.text = " "+posMins+":"+posSecs+" ";
songInfo.text = ""+posTime+""
myMusic.onSoundComplete = function() {
if (curTrackNum == (myMusicLv.totalTracks) -1) {
curTrackNum = 0;
} else {
curTrackNum++;
}
playMusic();
};
myMusic.onID3 = function() {
trackInfo.text = myMusic.id3.TIT2;
trackCount.text = myMusic.id3.TRCK;
};
myMusic.onLoad = function(success) {
if (!success) {
trackInfo.text = "Failed to load track.";
}
}
myMusic.loadSound("mp3s/mp3-"+curTrackNum+".mp3", true);
Sound Position And Duration
The sounds come from an array, when I click on the sound icon a new mp3 is loaded, that part works. The problem is with the txtPlayTime.text, when I load a new mp3 soundPlayingTime does not initialize from 00:00 but continues counting and the content of the text field txtPlayTime.text bliks from 00:00 / 00:00 to the current value every time the interval refreshes.
I tried all kind of things but I cannot make it work properly. Any help will be appreciated.
Thank you in advanced,
Attach Code
sound_interval = setInterval(updateSoundProgress, 100, s);
function updateSoundProgress(the_sound:Sound):Void
{
//Playing Time
var s_seconds:Number = the_sound.position/1000;
var spminutes:Number = Math.floor(s_seconds/60);
var spseconds = Math.floor(s_seconds%60);
if (spseconds < 10)
{
spseconds = "0" + spseconds;
}
var soundPlayingTime = spminutes + ":" + spseconds;
//Total time
var sTotalSeconds:Number = the_sound.duration/1000;
var stminutes:Number = Math.floor(sTotalSeconds/60);
var stseconds = Math.floor(sTotalSeconds)%60;
if (stseconds < 10)
{
stseconds = "0" + stseconds;
}
var soundTotalTime = stminutes + ":" + stseconds;
txtPlayTime.text = soundPlayingTime + " / " + soundTotalTime;
}
Sound.position And Sound.duration On Flash Lite 2.1
I'm using the code below to trace the position and duration of a loaded mp3 file. This works fine when I export as normal flash 9 version swf, though when I export as flash lite 2.0 or 2.1, the trace returns 0 for both position as well as duration. Here is suggested that the two members should be available for all flash lite 2.x versions. Is there a way to find the duration and position of an mp3 file in flash lite 2.x? Am I doing something wrong?
Thank you in advance,
Harry
Attach Code
var mySound:Sound = new Sound();
mySound.onLoad = function(success){
if(success == true) {
mySound.start(0, 0);
}
}
mySound.loadSound("sound.mp3");
function onEnterFrame() {
trace(mySound.duration + " " + mySound.position);
}
Edited: 02/05/2008 at 08:42:28 PM by Harry Vermeulen
Duration Of A Sound Object?
Is there a way to get the full duration of a sound object BEFORE it is compleatly loaded?
I am using
Code:
this.duration/1000;
right now to get the duration of the sound in seconds, but becouse the sound is streaming it seems the duration gets longer as the sound loads more, and more.....
Can anyone please help?
Thanks
~Gabor
ID3 And Sound Object Duration
Hey all,
I have been building out a simple audio player but seem to be having some difficulty acquiring the total duration of the mp3 file. Intially I tried to get the duration via onID3, this however returns a value slitgly smaller than what it should be. It gives me a time of 1:21, where it should be 1:25.
I eventually solved it by changing the function trigger from on ID3 to onLoad. This fixed the issue and gave me the correct time. However, upon further testing I realized that people using this would have to wait for the entire sound clip to load in order to see the value.
Is there a better way of achieving the .duration, do I have to add some kind of buffer to allow more to load?
Glitch With Sound.position And External Mp3 Sound Object
Hi,
I am in the midst of build a flash mp3 player and have chosen to load all of my mp3s externally and streaming using this method:
sndAudio.loadSound(track01, true);
The problem I am running into is that when track01 starts playing and I switch to another sound i.e.:
sndAudio.loadSound(track02, true);
the value in sndAudio.position doesn't get reset. This is causing havoc for me in my pause function and my counter as well... I am guessing I have to somehow delete the sound object and repopulate it when I stop a sound or start a different one but I am having trouble figuring this out. Has anyone had any luck with this before? Here is how I am initializing my sound object:
this.createEmptyMovieClip("mcSoundHolder", this.getNextHighestDepth());
var sndAudio:Sound = new Sound(mcSoundHolder);
I am running Flash MX 2004.
Thanks to anyone who can lend a hand,
Cheers,
T-Dawg.
Sound Object: LoadSound: Position
Hi there.
So I've just built a simple audio player in Flash MX for a project. I'm loading external MP3s with the loadSound() method of the Sound object.
Works fine.
I also have a progress bar that displays the percentage of the file that's been played. This works also, except...
...if I click to reload the sound while it is playing, even though it resets to the beginning of the sound, the script is still getting the position property as if the original sound had not been stopped.
Since there is no "unLoadSound()" function, I assumed that subsequent calls to loadSound() would result in the previous sounds getting destroyed.
Anyway, needless to say, this is frustrating me...how can I reset my visual progress bar so that it goes back to the beginning?
(I suppose I could create an entirely new Sound object on each click, but it seems like that would waste memory.)
Sound Object Position Dumbness
heres the deal.
i have created a sound object and am loading in mp3s into it from a server.
i have an animation that runs while the selected mp3 is loading and it does this by checking to see if either the position of my sound object is undefined or no greater than 0.
this works fine on my comp when i load the mp3s from my comp because when ever a new song is clicked the position property displays it as beginning at 0 which seems like what it should do.
heres the problem.
when i actually stream the mp3s from a server, and run a trace on the position property it does not reset to 0 when a new song is loaded in like on my comp. it just shows the time that the last stopped playing until the new song is loaded in and then it continues from the previous time although the song start at the beginning as usual.
can anyone tell me why this is and if there is a way i can fix it?
Object Position Effect The Panning Of Attached Sound
hey guys from one of the tutorials found on action script or flaskit i have started to create and adapt my own thing...... for now i have used the sound files from the tutorial... but they will change once i have them......
right then....... urm!lol
i have made it so that the volume of the sound attached to each duplicate movie clip is contolled by its possition on -y. i have also tried to make each MC do the same but for the panning control, with its left right possition...... but somethings gone wrong......
i have tried to addapt several tutorials to try and complete this task......
each Mc has to be started from the current position other wise all the location points will be out, after working this problem out i want to experiment with putting behaviours on each block so that they can be thrwn accross the stage and bounce and colide with oneanother... with all this i think that the sounds produced could be cool and interesting, with a variation on user and computer control....... hmmmm what do you think????
ok just zipped my file and it was 26.1mb from 32.....so i shal type the code i have used.actually its not letting me attach anything....*cries
too confusing so i took some screen shots...... this will confuse everyone........
no worries if no one replies cos it weell past my bed time aand have not done this very welll
Sound Object´s Position Stays Same After Loading Next Track
HI
I have created a simple mp3 player but it has a problem -
the sound object´s position property doesnt change(update) after first track has ended and second track has started playing. why?
here is all the code
Quote:
_soundbuftime = 5;
var $feedurl = "tracklist.xml";
feedXML = new XML();
feedXML.ignoreWhite = true;
feedXML.load($feedurl);
feedXML.onLoad = function(success) {
if (success) {
startPlaying();
}
};
this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth());
var stream_sound:Sound = new Sound(sound_mc);
var tracknum = 0;
function startPlaying() {
clearInterval(i);
delete pos;
if (tracknum == feedXML.childNodes[0].childNodes.length) {
tracknum = 0;
}
stream_sound.loadSound(feedXML.childNodes[0].childNodes[tracknum].childNodes[0].nodeValue, true);
stream_sound.start();
tracknum++;
}
stream_sound.onLoad = function() {
};
stream_sound.onSoundComplete = function() {
startPlaying();
};
play_btn.onRelease = function() {
if (!pos) {
stream_sound.start();
} else {
stream_sound.start(pos);
}
};
stop_btn.onRelease = function() {
pos = stream_sound.position/1000;
stream_sound.stop();
};
prev_btn.onRelease = function() {
if (tracknum == 1) {
tracknum = feedXML.childNodes[0].childNodes.length-1;
} else {
tracknum -= 2;
}
startPlaying();
};
next_btn.onRelease = function() {
startPlaying();
};
this.onEnterFrame = updateDisplay;
function updateDisplay() {
status_txt.text = "streaming............"+Math.floor(((stream_sound. position/1000)/(stream_sound.duration/1000))*100)+"%";
status2_txt.text = "Track "+tracknum;
status3_txt.text = stream_sound.position/1000;
}
onoff_mc.onPress = function() {
};
Getting The Duration And Position Of An Mp3
I have made a mp3 player which has all the right controlls. But I want to have a way to show the duration and position of a song like minutes.sekunds but the only way I have gotten it so far is:
Showduration=Math.round(_root.myMusic.duration/1000);
Showposition=Math.round(_root.myMusic.position/1000);
DurationPosition=Showposition+"/"+Showduration;
//And to get the minutes.sekunds interface of course you divide the Showduration & Showposition by 60 but then you have to get rid of the Math.round and then you get 0.0533333333333 yea you know what I mean!
So how can I show the sekunds skiping everything but whole sekunds?
Displaying Duration And Position
Im trying to make a flash music player, and im having trouble displaying the length of the track and the time played.
Here is the actionscript used, all it does is give me undefined/undefined. Im using flash mx 2004 pro. Any help would be appreciated.
Code:
this.onEnterFrame = function ()
{
dur = int(My_Sound.duration / 1000);
pos = int(My_Sound.position / 1000);
playTime = {};
playTime.minutes = int(pos / 60);
playTime.seconds = int(pos % 60);
playTime.total = checkDigits(playTime.minutes) + ":" + checkDigits(playTime.seconds);
trackTime = {};
trackTime.minutes = int(dur / 60);
trackTime.seconds = int(dur % 60);
trackTime.total = checkDigits(trackTime.minutes) + ":" + checkDigits(trackTime.seconds);
if (timetext.text == undefined){
timetext.text = playTime.total + " / " + trackTime.total
}
else
{
timetext.text = playTime.total + " / " + trackTime.total;
}
};
Position/Duration Display For FLV
I've created a FLV jukebox using the List component to hold the track names and I've bound it to a single instance of the FLVPlayback component. Clicking on a title on the List will load the corresponding .flv into the FLVPlayback component. I've also got a linked .as file to make the playlist play one .flv after the other. All is working perfectly.
The question: Is there a way to integrate a text display that will show the current playhead position and total duration time data for each file when it loads? (i.e. 2:29/4:25, like Windows MediaPlayer does)
P.J.F.
Sound.duration Lags Behind Sound.getBytesLoaded()
This is crazy:
Code:
l = 1779801 t = 1782285 p = 99.8606283506846 dur = 210
l = 1782285 t = 1782285 p = 100 dur = 211
l = 1782285 t = 1782285 p = 100 dur = 212
l = 1782285 t = 1782285 p = 100 dur = 213
l = 1782285 t = 1782285 p = 100 dur = 213
l = 1782285 t = 1782285 p = 100 dur = 214
l = 1782285 t = 1782285 p = 100 dur = 215
l = 1782285 t = 1782285 p = 100 dur = 215
l = 1782285 t = 1782285 p = 100 dur = 216
ActionScript Code:
var l:Number = my_sound.getBytesLoaded();
var t:Number = my_sound.getBytesTotal();
var per:Number = (l/t)*100;
//
trace("l = " + l +" t = " + t +" p = "+per+" dur = "+Math.round((my_sound.duration/1000)));
Has anyone ever experienced this problem of the Sound.duration property lagging behind the Sound.getBytesTotal()? This seems rather ridiculuos! And yes, this happen online too, not just locally!
Date Object And Attached Time/duration
hi folks,
i've got a problem with the date object.
i created one that gives the current time, date and so on, and one at which are 3600 seconds are attached, so that i get the time, date and so on after that specific duration, but the current date object seems to get overwritten. what's the matter with this one? please help.
http://pastebin.coconut.se/?id=4551
thanks
[flash8] Issues With Getting The Duration From A NetStream Object
I'm loading a .flv file with the NetStream object within a class. I'm trying to get the duration of the video through the onMetaData event but I can't seem to take that information out of the function (if I try to access the data or trace the value I get undefined).
Code:
import mx.utils.Delegate;
import caurina.transitions.Tweener;
class PresentationSlideshow.VideoPlayer.VideoScaffold extends MovieClip {
private var _stageWidth:Number = Stage.width;
private var _stageHeight:Number = Stage.height;
private var _ncConnection:NetConnection;
private var _nsStream:NetStream;
private var _flv_mc:MovieClip;
private var _audio_sound:Sound;
private var _isPlaying:Boolean = true;
private var _isMuted:Boolean = false;
private var _videoDuration:Number = 0;
public function VideoScaffold(path:String, vWidth:Number, vHeight:Number){
buildScaffold(path, vWidth, vHeight);
_root.movieContainer._alpha = 100; //this needs to be replaced with proper fade in code
loadVideo(path);
}
private function buildScaffold(path:String, vWidth:Number, vHeight:Number){
// Create container for movie
var movieContainer:MovieClip = _root.createEmptyMovieClip("movieContainer", _root.getNextHighestDepth());
// Attach the video objct within the empty movie
movieContainer.attachMovie("theVideo", "videoContainer", this.getNextHighestDepth());
// Set the container so the video is in the exact middle of the screen
movieContainer.videoContainer._width = vWidth;
movieContainer.videoContainer._height = vHeight;
movieContainer._x = (_stageWidth/2) - (vWidth/2);
movieContainer._y = (_stageHeight/2) - (vHeight/2);
movieContainer.attachMovie("videoControls", "videoControls", movieContainer.getNextHighestDepth());
movieContainer.videoControls._x = (vWidth/2)-225;
movieContainer.videoControls._y = vHeight + 40;
// Makes everything invisible
movieContainer._alpha = 0;
}
private function loadVideo(path:String):Void{
// get the video connected properly
_ncConnection = new NetConnection();
_ncConnection.connect(null);
_nsStream = new NetStream(_ncConnection);
_root.movieContainer.videoContainer.vMovie.attachVideo(_nsStream);
_nsStream.play(path);
// Attach the sound from the video to a new movie clip
this.createEmptyMovieClip("flv_mc", this.getNextHighestDepth());
_flv_mc.attachAudio(_nsStream);
var _audio_sound:Sound = new Sound(_flv_mc);
// Get the duration of the video
_nsStream.onMetaData = function(obj:Object) {
_videoDuration = obj.duration;
trace(_videoDuration);
}
// Mute Button code
var _isMuted:Boolean = false
_root.movieContainer.videoControls.volumeButton.onRelease = function(){
trace(_isMuted);
switch (_isMuted) {
case false :
trace("is false");
_audio_sound.setVolume(0);
_isMuted = true;
_root.movieContainer.videoControls.volumeButton.gotoAndStop("muted");
break;
case true :
trace("is true");
_audio_sound.setVolume(100);
_isMuted = false;
_root.movieContainer.videoControls.volumeButton.gotoAndStop("unMuted");
break;
}
}
// Scrubber codde
_root.movieContainer.videoControls.slider.onPress = function(){
this.startDrag(true, 75.5, 19.2, 375.5, 19.2);
trace(_videoDuration);
}
_root.movieContainer.videoControls.slider.onReleaseOutside = _root.movieContainer.videoControls.slider.onRelease = function(){
this.stopDrag();
}
// Button uses the Delegate class to force the button to play in proper scope
_root.movieContainer.videoControls.playPauseButton.onRelease = Delegate.create(this, playPauseEvent);
}
private function playPauseEvent():Void {
switch (_isPlaying) {
case true :
_nsStream.pause();
_isPlaying = false;
_root.movieContainer.videoControls.playPauseButton.gotoAndStop("playState")
break;
case false :
_nsStream.pause();
_isPlaying = true;
_root.movieContainer.videoControls.playPauseButton.gotoAndStop("pauseState")
}
}
}
I'm creating a video scrubber and I need the duration value to make it work. Any ideas?
--thanks
Sound Duration Bar, PLEASE HELP :)
i have made an mp3 player that loads mp3s from a dir on my server and streams them. i made a duration bar (duration_mc) to show how much of the song has elaped:
duration_mc.onEnterFrame = function(duration){
this._xscale=my_sound.position/my_sound.duration*100;
it works for the first song, but then when you click another track it will continue from where it left off on the previous song.
my question is, how can i make the duration bar reset to the beginning when you click to stream another song?
Get Sound Duration Without Id3?
Anyone know if it's possible to to acertain the duration of an externally-loaded mp3, either by time or frames? I'm working on a project where the user records a voice message as an mp3, which is then loaded into a .swf. The .swf contains a movie clip which is supposed to play while the Sound's playing, and stop when the Sound's finished. HOWEVER, the mp3s don't have an .id3.TIME property attached so that property can't be accessed . Many thanks.
How To Get Sound Duration?
i am loading mp3sounds .swf into empty movie clip how to get the sound duration of every song using dynamic text box..
About Sound Duration
Hi I'm newby here and I want some help.
I just building a MP3 Player and load the external MP3 file into flash and I load it as a stream. I want to get the duration of the song for update my progress bar and now I using "sound.duration" to get that but this value will change when the whole file is not loaded (I mean if it loaded 1 sec. it return 1sec so that is not the actualy song duration)
Is there any method to get the file duration at the begining of sound loaded.
thank you and sorry for my English
Get Sound Duration
hi everyone!
i'm trying to pass to a dynamic text field the duration of a sound in seconds.
how can i do that?
thanks
How To Get Sound Duration?
i am loading mp3sounds .swf into empty movie clip how to get the sound duration of every song using dynamic text box..
Sound Duration
hey guys,
I'm trying to use the sound property duration and position to change the background image of a MC.
when the sound is 25% done playing I want to tell another clip on the _root to gotoAndPlay frmae (2);
here's what I've tried
sound.onEnterFrame = function () {
if (sound.duration/4 == sound.position) {
_root.background_MC.nextFrame();
}
}
but it jsut sit there?
can do do this using onSoundComplete, but I want to change 4 time during the play back?
anyhelp?
jef
Sound Duration
I'm importing an MP3 on the fly and it's approx 69000ms seconds long.
However, when I trace the sound duration, it comes out 24890ms. It's losing 45 seconds The MP3 itself seems to be fine when I open it in sound forge. Anyone experienced this before?
Check For Sound Duration
Does anyone knows how to check for sound duration?? I mean using action script to check for it, not manually using stop watch. I have a music attached using scripts, I need to check that when the song ends, everything puts to a stop.
Any idea anyone??
Sound.duration + Levels
actionscript 1.0/2.0
Hi basically I have a really annoying problem - all I want to do is use sound.position to retrieve the number of milliseconds a particular sound has been playing.
Which I've done in a test harness program which uses the linkage feature to dynamically import sounds from the library and bring in to an empty movie clip and then control it from there.
However this flash swf is part of a bigger flash file (_level0.swf) which loads this test harness into an empty movie clip called 'content'and displays it.
However when played through _level0.swf, which ultimately loads the test harness into the content mc within _level0 - the sound plays - but refuses to divulge the amount of milliseconds the sound has been playing.
I've used all sorts of paths - which all work standalone in test harness - but fail when loaded through other _level0.swf.
It's doing my head in now! - one thing I did notice however when I first tried to do it it wouldn't even play the linked sound before I embedded it in a empty movie clip (even though all the code was correct and it played in test harness).
Any suggestions welcomed
Heres the code I have in test harness
Code:
current_audio = 1;
this.createEmptyMovieClip("sounds", 1);
this.sounds.sound_duration = 0;
function playReply(){
this.sounds["mc_sound_" + current_audio] = new Sound("sounds");
this.sounds["mc_sound_" + current_audio].attachSound("reply_" + current_audio);
this.sounds["mc_sound_" + current_audio].onSoundComplete = function (){
this.sounds.sound_duration = 0;
audio_button.gotoAndStop(1);
};
this.sounds["mc_sound_" + current_audio].start(this.sounds.sound_duration, 1);
audio_button.gotoAndStop(2);
}
function pauseReply(){
this.sounds.sound_duration = ((this.sounds["mc_sound_" + current_audio].position)/1000);
this.sounds["mc_sound_" + current_audio].stop("reply_" + current_audio);
}
where my sound and exported from the library using the identifers reply_1, reply_2 etc.
And on stage is an audio button with two states pause and play and clicking on them calls the appropriate function.
The othe paths I've tried are with no paths included and using _level0.content before it instead of this - which all work in test harness and not when played through the _level0 hierachy.
_level0 uses the following code to load test harness (activity into a manually created empty movie clip called 'content'.
Code:
content.loadMovie("testharness.swf");
[F8] Question About Sound Duration And XML
Hi!
I am making a sound player that gets the mp3 files from a xml file, plays them one by one and stops when it reaches the last file.
The thing is that I wanted to do a little crossfading thing between the tracks to make it nicer, but as I try to get a simple "showTune.duration" it returns 0 all the time. Is there a way to get the duration of the track without having to insert it manually on the XML?
Thanks for your time.
[F8] Problem With Sound.duration
I am working on a music player where the music list is loaded using xml. I am using sound object and the streaming property is set to 'true'. Now I want to calculate sound.duration, but I don't get the actual value when it is streaming, probably because the entire file is not downloaded at once because of streaming, and it is returning the duration of the portion of the file downloaded. So I am unable to develop a progress bar which shows the current position of the music.
I even tried to get the file duration using ID3 tag but the TIME property does not seem to work either.
Another options could be using php to get the duration of the mp3 file and generate an xml file which specifies the duration of the file.
But I have a little idea about php.
Can anyone help me
Sound Duration Issue
this code in frame 1:
Code:
s = new Sound();
s.loadSound("ms_basses2.mp3", false);
track_totalTime = s.duration;
returns this in the variable list when debugging:
Code:
duration:[getter/setter] 66194,
Variable _level0.track_totalTime = 0
is it just me or is there conflicting feedback there?
I may just not understand something about debugging this.
Undefined Sound.duration?
I've got a math lesson that I'm playing some feedback audio (short narration) using mySound.attachSound("linkage") and I want to make the buttons on stage not accessible until after the feedback.
I used delay=mySound.duration to get the duration of the sound and then I use setTimeout(enableButtons,delay);
It works fine in the testing environment or when I play just the published swf. But if I load that swf into an empty movieclip, mySound.duration returns "undefined." The sound does still play and the scoping is correct. Anybody have any ideas?
Pause Sound Duration
Here it is my duration function, play funtion and pause funcion
the problem is i can't find a way to stop the timer of the duration
the text field is called t1.
Thank you
this.onEnterFrame = function() {
t1 = int(sndObject.duration/1000/60);
t1 = t1+" : "+int((sndObject.duration/1000-(t1*60)));
sndObjectf = int((sndObject.duration-sndObject.position)/1000/60);
elapsed_sec = int((((sndObject.duration-sndObject.position)/1000/60)-sndObjectf)*60);
if (elapsed_sec<10) {
elapsed_sec = "0"+elapsed_sec;
}
if (sndObjectf<10) {
sndObjectf = "0"+sndObjectf;
}
if (_root.stpd) {
elapsed = _root.t1;
} else {
elapsed = sndObjectf+" : "+elapsed_sec;}
//mo=sndObject.position/1000
//elapsed =
vol = sndObject.getVolume()+" %";
dur = sndObject.duration;
pos = sndObject.position;
per = (pos/dur)*100;
m = (pos/dur)*100;
bar._width = (m*xx)/100;
drag._x = _root.bar._width+_root.bar._x;
//drag._y = 136;
if (stpd) {
xx = 0;
} else {
xx = orginal_width;
}}
// function keys
function playSong()
{
if (pausePos == 0)
{
sndObject.setVolume(songVolume);
sndObject.loadSound(file, true);
loadProgressInt = setInterval(loadProgress, 50);
} // end if
sndObject.start(pausePos);
playProgressInt = setInterval(playProgress, 50);
pauseBut._visible = true
playBut._visible = false;
gotoAndPlay("play");
dur = sndObject.duration;
} // End of the function
function pauseSong(p)
{
if (!p)
{
pausePos = sndObject.position / 1000;
}
else
{
pausePos = p;
} // end else if
sndObject.stop();
pauseBut._visible = false;
playBut._visible = true;
clearInterval(playProgressInt);
gotoAndPlay("pause");
} // End of the function
Problem With Sound Duration
Hi,
i have a mp3 player that works perfectly offline but once online the sound.duration seems to be incorrect. The sound.duration = 15' online and 52' offline. And it's the same for each mp3 with an incorrect duration.
You can see what i mean here :
http://adesign.tonsite.biz/v4
Any ideas ?
Thank's.
Chris
Streaming Sound Duration?
I have currently a music player that uses Sound.position and Sound.duration to use as a playlist. However, the sound is streaming, so then Sound.duration is the number of loaded seconds/miliseconds. Is there a way for me to figure out the duration of a sound without fully loading it? Right now, it really messes up the playhead.
Sound Duration, Problems
Hello!
I am crating a MP3 Player, and i have one problem to fix. When i use the my_sound.duration (where my_sound is var my_sound:Sound = new Sound(); ), the duration only shows correcty when i use the onLoad method. Exemple:
var my_sound:Sound = new Sound();
my_sound.loadSound ("my file.mp3", true);
my_sound.onLoad = function() {
duration_txt.text = my_sound.duration;
}
But, i dont want wait the music complete loaded to show the duration, but when the music starts show the duration.
I cant use the id3.LEN on my file. The other soluction is put the duration information in a XML file and later show in the Flash, but i want somethig ease, more dinamic.
So, have soluction to my problem or i have to say the duration of the Music.
Thanks
Ps: Sorry for my English
Sound.duration Problem
I am working on a music player where the music list is loaded using xml. I am using sound object and the streaming property is set to 'true'. Now I want to calculate sound.duration, but I don't get the actual value when it is streaming, probably because the entire file is not downloaded at once because of streaming, and it is returning the duration of the portion of the file downloaded. So I am unable to develop a progress bar which shows the current position of the music.
I even tried to get the file duration using ID3 tag but the TIME property does not seem to work either.
Another options could be using php to get the duration of the mp3 file and generate an xml file which specifies the duration of the file.
But I have a little idea about php.
Can anyone help me
Problem With Sound Duration
Hi,
i have a mp3 player that works perfectly offline but once online the sound.duration seems to be incorrect. The sound.duration = 15' online and 52' offline. And it's the same for each mp3 with an incorrect duration.
You can see what i mean here :
http://adesign.tonsite.biz/v4
Any ideas ?
Thank's.
Chris
Sound Duration - Problem
Hello!
I am crating a MP3 Player, and i have one problem to fix. When i use the my_sound.duration (where my_sound is var my_sound:Sound = new Sound(), the duration only shows correcty when i use the onLoad method. Exemple:
var my_sound:Sound = new Sound();
my_sound.loadSound ("my file.mp3", true);
my_sound.onLoad = function() {
duration_txt.text = my_sound.duration;
}
But, i dont want wait the music complete loaded to show the duration, but when the music starts show the duration.
I cant use the id3.LEN on my file. The other soluction is put the duration information in a XML file and later show in the Flash, but i want somethig ease, more dinamic.
So, have soluction to my problem or i have to say the duration of the Music.
Thanks
Ps: Sorry for my English
Streaming Sound Real Duration...
Everybody knows that .duration property shows the duration of the part loaded when talking about streaming sound. I predefine such a method:
Sound.prototype.realDuration = function() {
return (this.getBytesTotal()/this.getBytesLoaded())*this.duration;
}
But it returns different values while loading too... Why so? Is there any effective solution?
Sound.duration Problem.. Xml Mp3 Player
Hi guys/gals..ive made an xml driven mp3 player...everything is working fine expect the playback progress head.. its works FINE locally.
The problem is online. For some reason intially the sound duration property keeps changing (instead of being a CONSTANT) until it reaches its final constant value.
You can look at this at http://www.flashmatics.co.uk/blog/sa...mp3player.html
Therefore obvisuoly the playhead is out of sync with the song
Does anyone have an idea why/how this is so?why is the duration property changing when it should be a constant? Thanks..ive made players before but never experienced this problem..
Any help appreciated..cheers
How Do I Display The Sound Duration Property?
Hi.
I have the code below for my mp3 player. It works fine. I found the code on 'sound duration' in the Flash help section on how to get the duration of a song. But how do I actually display the info in a dynamic text box?
function playMusic() {
myMusic = new Sound();
// get Duration Property onLoad
myMusic.onLoad = function(success:Boolean) {
var totalSeconds:Number = this.duration/1000;
trace(this.duration+" ms ("+Math.round(totalSeconds)+" seconds)");
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
trace(minutes+":"+seconds);
};
myMusic.onSoundComplete = function() {
if (curTrackNum == (myMusicLv.totalTracks) -1) {
curTrackNum = 0;
} else {
curTrackNum++;
}
playMusic();
};
myMusic.onID3 = function() {
trackInfo.text = myMusic.id3.TIT2;
trackCount.text = myMusic.id3.TRCK;
};
myMusic.onLoad = function(success) {
if (!success) {
trackInfo.text = "Failed to load track.";
}
}
myMusic.loadSound("mp3s/mp3-"+curTrackNum+".mp3", true);
How Do I Display The Sound Duration Property?
Hi.
I have the code below for my mp3 player. It works fine. I found the code on 'sound duration' in the Flash help section on how to get the duration of a song. But how do I actually display the info in a dynamic text box?
function playMusic() {
myMusic = new Sound();
// get Duration Property onLoad
myMusic.onLoad = function(success:Boolean) {
var totalSeconds:Number = this.duration/1000;
trace(this.duration+" ms ("+Math.round(totalSeconds)+" seconds)");
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
trace(minutes+":"+seconds);
};
myMusic.onSoundComplete = function() {
if (curTrackNum == (myMusicLv.totalTracks) -1) {
curTrackNum = 0;
} else {
curTrackNum++;
}
playMusic();
};
myMusic.onID3 = function() {
trackInfo.text = myMusic.id3.TIT2;
trackCount.text = myMusic.id3.TRCK;
};
myMusic.onLoad = function(success) {
if (!success) {
trackInfo.text = "Failed to load track.";
}
}
myMusic.loadSound("mp3s/mp3-"+curTrackNum+".mp3", true);
Reset Sound Positon/duration
Im trying to make a flash mp3 player using the loadSound command and I cant figure out how to make the mysound.position/duration property reset when I change the song thats playing. Also when I go to the next song and then return to the previous song flash has memorised the old position?? How do I stop this?
Sound.duration For Streaming Contents
Is it possible to know the duration of a streamed MP3 before it is fully loaded? Sound.duration gives only the amount that has been loaded. The Sound.id3.TLEN gives undefined.
Sound Duration = MyBar Width
Hi to all!:
Hope u can help me out. I´ve built a bar that grows as the sound is played. In the code I'm using, the position of the sound is expressed in milliseconds.
Code:
position = _root.track1.position/1000;
_root.myBar._xscale = position;
The thing is that i'd like to equal the bar width (250 pixels) with the total sound duration. So when the sound has got to the end, the bar has fully grown to 205 pixels.
I´ve already checked the Kenny Bellew tutorial, but still can't figure out how this precise issue is solved.
Thanks in advance!!!...
Trouble Accessing Sound Duration - Help
I can't seem to access the sound duration value in my code, I am not sure what I am doing wrong.
ActionScript Code:
var directory:String = "Voices/";var noOfSongs:Number = 100;var aSongs:Array = [];var currIndex:Number = 0;for (var i = 1; i<=noOfSongs; i++) {aSongs.push("v"+i+".mp3");}VSound = new Sound(Voice1_mc);function playSound(songIndex:Number):Void {VSound.loadSound(directory+aSongs[songIndex], true);VSound.setVolume(VSound.getVolume()+50);trace(VSound.duration);VSound.start(0, 0);}VSound.onSoundComplete = function() {currIndex++;if (currIndex == aSongs.length) {currIndex = 0;}playSound(currIndex);};playSound(currIndex);
Sound Duration = MyBar Width
Hi to all!:
Hope u can help me out. I´ve built a bar that grows as the sound is played. In the code I'm using, the position of the sound is expressed in milliseconds.
Code:
position = _root.track1.position/1000;
_root.myBar._xscale = position;
The thing is that i'd like to equal the bar width (250 pixels) with the total sound duration. So when the sound has got to the end, the bar has fully grown to 205 pixels.
I´ve already checked the Kenny Bellew tutorial, but still can't figure out how this precise issue is solved.
Thanks in advance!!!...
|