updated 25 sept 2002 | brown | green | blue | grey
daryl croke
research diary
edim 2002

Week 12:

Streaming Sound with Flash

In week 11 building a sound console using mySound.position and mySound.duration was discussed. Although the console allowed a lot of functionality download time especially for dial up connections could be considerable. It is possible to build a preload movie to keep the user both visually and aurally entertained but for many potential users waiting is still annoying.

Flash MX allows developers to stream audio by loading an mp3 into a sound object.

mySound = new Sound ();
      mySound.loadSound("URL", streaming);
      mySound.start();

The "url" refers directly to an m3p eg "narration.mp3" and streaming is either true to stream a sound or false to play the sound as an event sound. If streaming is set to false then flash will wait for the whole of the sound to load before playing. When streaming is set to true a then the sound will begin to play after a default 5-second delay. Streaming sounds play before the whole of the audio file is downloaded.

It is relatively easy to build a sound function that loads and plays a streaming mp3.

  function playSound() {
      mySound = new Sound ();
      mySound.loadSound("soundfile.mp3", true);
      mySound.start();
 }

A streaming sound can be stopped via a button in the following manner.

stop_button.onRelease = function() {
      mySound.stop();
      }

To restart call the sound function.

play_button.onRelease = function() {
      playSound();
 }

Flash Streaming with basic controls

The complication occurs if a developer wants to resume from the stop/pause point. Although with the latest plugin from flash to track sound.position it is simply not possible to restart from the any position other than zero, the very start of the file. Logically the following code should work for a streaming sound.

function playSound() {
      mySound = new Sound ();
      mySound.loadSound("soundfile.mp3", true);
      mySound.start(playtime, 0);
   }

Flash Streaming tracking sound.position

It appears that the functionality of mySound.loadSound is to restart the audio file from the very start making mySound.start() obsolete. A more constructive approach would have seen mySound.loadSound() simply pass the streaming audio file to the variable mySound. Developers could then pause, play, rewind the streaming audio at will.

An insight into the problems a building functionality using mySound.loadSound() can be found at.

http://www.flashguru.co.uk/000100.php

What flash audio developers do to gain functionality when using streaming audio is to convert mp3 files to Flash SWF files and control the external "sound only" SWF files via a sound console. There are a number of tools to make this process easier.

Swift mp3 is a free PC based tool that automatically converts mp3 files to flash movies. A nice feature is that non-audio information, such as title; artist, album etc can be imbedded in the movie and retrieved later. Swift has a spectrum analyser that records EQ levels over time.

http://www.swift-tools.com/

This is one method that developers use to produce those groovy dynamic audio level indicators.

http://flash.onego.ru/flash5/cleoplayer2/cleoplayer2.html

Another advantage of using sound only flash files is the ability to control the audio by javascript buttons. One way to achieve this is FlashSound API

http://www.sonify.org/flashsound/index.html

In the early research phase of this project I experimented using Javascript to control flash movie but found that it wasn’t support very well on the Macintosh platform. The flashSound page warns that the examples given wont work on Internet Explorer on a Mac.

Continue to week 13.