Adobe AIR:如何播放本地mp3文件?
我正在使用 Flex 测试 Adobe AIR,我想通过打开的文件对话框播放 mp3,我这样做了:
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();
}
但是当我尝试打开文件时,在“打开文件”对话框关闭后,我收到此错误:
TypeError: Error #1034: Type Coercion failed: cannot convert "file:///C:/Users/Kedare/Music/05-Scene%20V%20~%20Prelude.mp3" to flash.net.URLRequest.
我可以'在 Google 或其他文档上找不到与此相关的任何内容,我找到的所有文档都与使用 URL 而不是本地文件播放声音有关:(
知道可能是什么问题吗?我能做什么?
谢谢!
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
为
Change
to