Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-31-2008, 02:46 AM   #1
zoransoko
Registered User
 
Join Date: Mar 2008
Posts: 5
Unhappy Strange thing about SoundChannel.position!!!

This is really

I want to load the sound from a different server then the one where my mp3 player is.I had a problem with my scrubber that didn't wanted to play from the position I entered after releasing the scrubber:

var pausedPosition:int = channel.position;
channel.stop();
channel = sound.play(pausedPosition);


After two days of trying "everything" with my player I decided to test the code from
http://livedocs.adobe.com/flash/9.0/...ndChannel.html
(the example below stop() method)

I wrote this code:
ActionScript Code:
var snd:Sound = new Sound(); var channel:SoundChannel = new SoundChannel(); var button:TextField = new TextField(); var req:URLRequest = new URLRequest("http://www.kafanasokace.co.yu/srpski/Kod Ovako Divne Noci.mp3");//this is the sound I want to load snd.load(req); button.x = 10; button.y = 10; button.text = "PLAY"; button.border = true; button.background = true; button.selectable = false; button.autoSize = TextFieldAutoSize.CENTER; button.addEventListener(MouseEvent.CLICK, clickHandler); this.addChild(button); function clickHandler(e:MouseEvent):void {    var pausePosition:int = channel.position;    if (button.text == "PLAY")    {       channel = snd.play(pausePosition);       button.text = "PAUSE";    }    else    {       channel.stop();       button.text = "PLAY";    } }

...and uploaded the player to a different server.Here:
http://zi.freehostia.com/player/player.html

When I test the player from my local computer from within Flash CS3 play/pause button works fine but when I test it in above URL (in IE and Firefox) when I press 'play' after pressing 'pause' sound doesn't play from the last position.It plays from 1-2 seconds after the last position. According to this I can not build a precise scrubber and the scrubber even won't work.

I tried with uploading crossdomain.xml file in root of the site from where I want to load the sound file but it didn't help.


Can someone tell me what causes the problem I am having?


Thanks.
zoransoko is offline   Reply With Quote
Old 04-01-2008, 11:09 AM   #2
ryancameron
Registered User
 
Join Date: Dec 2006
Posts: 4
Question problem with sound.play(cue point)

The new AS2/3 sound stuff is pretty buggy for me too. My scrubber works inside the dev environment fine, but running it locally but outside the IDE and my cuepoints get all skewed, seems like AS3 reports either the wrong length for the sound, or just wrong soundChannel position values.

Anyone run some comprehensive tests on this to see what is going on here?

In order to get to a position, I am using the following:

mySoundChannel.stop();
mySoundChannel = mySound.play(newPosition)

that rather nonsensical code seems to be the only way in AS3 to get the seek /scrubber to work, but it seems like stopping transport could be the issue, but just using the play command by itself has no effect.

we really need a seekTo method for the soundChannel imho.
ryancameron is offline   Reply With Quote
Old 04-01-2008, 02:14 PM   #3
ryancameron
Registered User
 
Join Date: Dec 2006
Posts: 4
Default

I found a workaround, basically if your sample rate is less than 44.1k, you need to divide the sound.duration by the proportion. So if you have a sample rate of 11.025k, you divide the duration by 1/4.

IE:
var mySound:Sound = new Sound();
var sampleRate:int = 11025;
var proportion:Number = 44100/sampleRate
var actualDuration = mySound.duration/proportion

then use actualDuration for your position calcs. This will malfunction locally in the flash IDE, but will work properly when published and run from the web.

I am unable to find a way to dynamically determine the sample rate of a file as yet. Windows media player doesnt show it, but VLC media player does under view-->stream and media info.
ryancameron is offline   Reply With Quote
Old 04-01-2008, 03:02 PM   #4
zoransoko
Registered User
 
Join Date: Mar 2008
Posts: 5
Default Fanny thing when the server errors can take 5 days from you

I found a free server on internet and tested my code on it.
Everything worked.


ryancameron, if your code works in some environment and doesn't in another, try to change the server.
I lost 5 days and a lot of nerves when I discover that my server is not working properly, probably for a few days......
zoransoko is offline   Reply With Quote
Old 04-01-2008, 05:33 PM   #5
zoransoko
Registered User
 
Join Date: Mar 2008
Posts: 5
Default

Yes ryancameron. That was also a part of my problem. But in this case all mp3s that I will load are 44100Hz.

If you are loading mp3s from the same server try to load Id3Info from your sound file.
Actually I didn't see if there is such a property, but Look at this:
http://livedocs.adobe.com/flash/9.0/...Sound.html#id3

But if you are loading your sound files from a different server loading id3Info could produce errors because this is very buggy in ActionScript 3.0

Anyway winamp lets you see the sample rate so if it helps just read it and put in some XML file or flashvars parameter.
zoransoko is offline   Reply With Quote
Old 07-11-2008, 02:20 AM   #6
birnamdesigns
Registered User
 
Join Date: Jul 2008
Posts: 1
Default

If anyone is still getting frustrated with this one, I've written a couple of classes that will evaluate the sample rate and adjust the playback point and position property accordingly. It's not well tested, but if it will help you're welcome to it.

The classes are Sound2 and SoundChannel2 (creative, I know). The only difference between them and the original Sound/SoundChannel in use is that you can use the Sound2.play2() function (instead of play) and it will return a SoundChannel2 object instead of a SoundChannel object. the SoundChannel2 object automatically corrects the position property. Sound2 will return the COMPLETE load event after the audio has both loaded and been evaluated for sample rate. There load time for the audio files will increase by about one second for the evaluation process. The files are reasonably well documented I hope.

http://www.birnamdesigns.com/misc/as...d2_classes.zip
birnamdesigns is offline   Reply With Quote
Old 07-30-2008, 10:33 AM   #7
AXAY
Registered User
 
Join Date: Jul 2008
Posts: 1
Default birnamdesigns' soulution doesn't work sometimes

I have tried this solution posted by birnamdesigns. I have tested and found that most of the time it works fine for my pause-play functionality. But sometimes it doesn't work fine. This happens in the initial few seconds of songs. Seems like this will not work in the initial few seconds when sound is loading. Is there anything else other then SoundChannel2, Sound2.play2() that I should modify? Please help...
AXAY is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are my instance names changing..? Strange problem. SnowboardKid ActionScript 2.0 4 11-14-2005 12:55 AM
RadioButton inside Datagrid..Strange behaviour superprg Components 0 11-05-2005 09:21 AM
strange thing with my loader Obscurus ActionScript 2.0 5 11-05-2005 02:18 AM
Load Movie. Urgent. Strange thing Gerebeto ActionScript 1.0 (and below) 10 07-27-2003 07:02 PM
(arg) ? thing; : otherThing; buggedcom ActionScript 1.0 (and below) 11 05-11-2003 03:13 PM


All times are GMT. The time now is 03:48 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.