Skip to main content
Participating Frequently
September 18, 2011
Question

HELP! How to play a sound from android SD card

  • September 18, 2011
  • 1 reply
  • 714 views

Hello,

How do I call a sound from an external location on Android. Does anyone have some sample code? Ideally I want a wav or mp3 file to be located in the internal memory of the SD card.

I have not been successfully in calling the sound. Please help... thanks

Here is come code... What have I done wrong?

//number that is redefined when the pause button is hit

var pausePoint:Number = 0.00;

//a true or false value that is used to check whether the sound is currently playing

var isPlaying:Boolean;

//think of the soundchannel as a speaker system and the sound as an mp3 player

var soundChannel:SoundChannel = new SoundChannel();

var sound:Sound = new Sound(new URLRequest("\mnt\sdcard\download\sundaymorning.mp3"));

//you should set the xstop and xplay values to match the instance names of your stop button and play/pause buttons

xstop.addEventListener(MouseEvent.CLICK, clickStop);

xplay.addEventListener(MouseEvent.CLICK, clickPlayPause);

soundChannel = sound.play();

isPlaying = true;

function clickPlayPause(evt:MouseEvent) {

    if (isPlaying) {

        pausePoint = soundChannel.position;

        soundChannel.stop();

        isPlaying = false;

    } else {

        soundChannel = sound.play(pausePoint);

        isPlaying = true;

    }

}

function clickStop(evt:MouseEvent) {

    if (isPlaying) {

        soundChannel.stop();

        isPlaying = false;

    }

    pausePoint = 0.00;

}

This topic has been closed for replies.

1 reply

Adobe Employee
September 19, 2011

Could you replace backslashes in the file's path with forward slashes:

"/mnt/sdcard/download/sundaymorning.mp3"

Participating Frequently
September 22, 2011

No, it doesn't.... help!!! Any way I can debug this??? Anyone know how to simply play a sound in Android?!