1

How would i go about caching sound assets in Flex, I load the sounds for play via:

            private function set_streamingMedia(mediaURL:String) : void {

            var req:URLRequest = new URLRequest(mediaURL);

            if (streamChannel) {
                streamChannel.stop()
            }

            auth_play(req);
        }

        private function auth_play(reqestURL:URLRequest) : void {

            stream = new Sound();

            var credsHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + credentials);
            reqestURL.requestHeaders.push(credsHeader);

            var context:SoundLoaderContext = new SoundLoaderContext(1000, true);

            stream.load(reqestURL, context);

            timer = new Timer(100);
            timer.addEventListener(TimerEvent.TIMER, mediaPositionChange);

            play();

        }

            private function play():void{               
            if(isPaused){
                streamChannel = stream.play(trackPosition);
                timer.start();
                isPaused = false;
            }
            else{
                if (streamChannel) {
                    stop();
                }
                streamChannel = stream.play();
                timer.start();
                isPaused = false;
            }
            ChangeVolume();
        }

I am on the playbook, so I can save it in a directory, put it in as a BLOB on SQLite (seems like a terrible idea) - Ideas would be much appreciate.

Also want to thank all the people here who have been taking the time to teach me Flex :) - you guys are better than the book I spent money on!

Omar Mir
  • 1,500
  • 1
  • 19
  • 39
  • Why would you cache streaming sounds in the first place? This would get out of hand *very* quickly, especially if it's on a mobile device. Plus, I don't think it's possible to save the bytearray of a streaming sound into a file. – J_A_X Aug 09 '11 at 06:22
  • Well the device ranges in space from 16GB to 64GB and the user has a choice on caching for offline use. They will not always be online to use it, Its relatively common practice now no? Lots of my music streaming services cache music for future offline usage (Real's service comes to mind). – Omar Mir Aug 09 '11 at 19:07
  • yeah, but that's a bit different. The problem here is that I don't think you can 'save' streaming data locally using Flash/Air (it's a limitation). You can ask on the adobe forums and file a bug (if one isn't there already). The only way to really 'cache' would be to get a physical file (mp3 or something) and save it locally. – J_A_X Aug 09 '11 at 23:28
  • I see - possible to get the file via the filrefrence class - save it and then start playing as it is downloading? Makingit seem like its caching but actually downloading? – Omar Mir Aug 10 '11 at 06:52
  • 2
    Essentially, yes. The only thing is that you don't 'stream' it because you're getting the file directly. It might be in your best interest to have it stream to the device at first (like a preview or the whole thing) and the user can choose if they want to download it for later. – J_A_X Aug 10 '11 at 07:05
  • J_A_X would you mind posting a small sample of how to download the file and start playing it as it's downloading - I would like to accept that as the solution. Nothing in depth but just something to get me started. – Omar Mir Aug 10 '11 at 21:02
  • Again, you can't do that. You can't 'stream' a file to play, but you can stream normal audio/video while downloading the real file. – J_A_X Aug 10 '11 at 23:30

0 Answers0