Kedare
Kedare

Reputation: 1277

Adobe AIR: How to play local mp3 file?

I'm testing Adobe AIR with flex, and I wanted to play a mp3 via an open file dialog, I did that :

import flash.filesystem.*;
import flash.events.Event;
import flash.media.*;
import mx.core.SoundAsset;

public var loadedFile:File;
public var channel:SoundChannel;
public var song:SoundAsset;


private function loadFile():void {
 loadedFile = new File();
 loadedFile.browseForOpen("Open multimedia File");
 loadedFile.addEventListener(Event.SELECT, fileSelected);
}

private function fileSelected(event:Event):void {
 song = new SoundAsset()
 song.load(URLRequest(loadedFile.url));
 channel = song.play();
}

But when I try to open a file, after the Open file dialog close, I get this error :

TypeError: Error #1034: Type Coercion failed: cannot convert "file:///C:/Users/Kedare/Music/05-Scene%20V%20~%20Prelude.mp3" to flash.net.URLRequest.

I can't find anything related to that on Google or another documentation, all the docs I find is related to play a sound using URL and not Local files :(

Any idea of what can be the problem ? What can I do ?

Thank you !

Upvotes: 1

Views: 4612

Answers (1)

Cory Petosky
Cory Petosky

Reputation: 12656

Change

song.load(URLRequest(loadedFile.url));

to

song.load(new URLRequest(loadedFile.url));

Upvotes: 5

Related Questions