0
votes

Just looking for some advice and hoping someone can point me in the right direction.

I'm trying to create a Flash MP3 player that can play music stored on DropBox. Never used ActionScript before so kind of learning as I go...

From what I've read so far, I need to use URLRequest to get the link to the mp3 file, then use the Sound object to load the file and play it. However, when I test my SWF file I don't get audio. I've also been reading about URLSream and NETstream, but not sure how to use that with the Sound object. I'm not 100% sure if I'm using Sound correctly, and given that this is pretty old technology now, I'm struggling to find decent tutorials.

Here's the code I've been trying:

package  {
    //Dependencies
    import flash.display.MovieClip;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import flash.net.URLStream;
    
    import flash.display.*; 
    import flash.events.*; 
    import flash.net.*; 
    import flash.media.*; 
    
    //Class code
    public class soundObject extends MovieClip {
        
        //Variables
        var mySong:Sound = new Sound();
        
        //Init Code here
        public function soundObject() {
        
            var myRequest:URLRequest = new URLRequest("https://www.dropbox.com/s/[dropboxurl]/T-U-R-T-L-E%20POWER.mp3?dl=0")
            mySong.load(myRequest);
            mySong.addEventListener(Event.COMPLETE, onSoundLoad);
            
        }
        
        private function onSoundLoad(e:Event): void
        {
             mySong.play();
        }
    
}

}
1
The script looks fine, it will most probably work if you try loading audio files from the same location where the other files (SWF, specifucally) are. So, there are two possible problems. 1. Cross-domain issues. Flash has a strict scheme of rules what it can and cannot obtain (and access once obtained) from the iternet. 2. More probably, DropBox download link does not return MP3 file data straight away, but rather some kind of proxy HTML page to start the download, which makes a lot of sense for browser, yet not that much for the Sound instance. - Organis
I did put the file locally and it worked fine. I know the link works, because I'm trying to recreate another flash player I've seen. That player must download the mp3 and cache it before playing, so need to figure out the trick. - ElCodes
Well, use URLLoader with URLLoaderDataFormat.BINARY data format rather than Sound to learn, if that request produces the actual MP3 data or HTML page. - Organis
The Dropbox shared link URL does not return the file data directly by default; it points to an HTML preview page. You can modify it for direct file content access though, as documented here: help.dropbox.com/files-folders/share/force-download - Greg
@Organis. I have not looked into URLLoader yet. I'll check that out. Thank you. - ElCodes

1 Answers

1
votes

So I figured it out guys... and surprise, surprise, it was something rather simple.

In publish settings, I had it set to 'local only'. When I changed this 'network only' the link started to magically work.

Thanks for the help. Got there in the end :D

EDIT: And just in case, I did also have change ?dl=0 to ?dl=1