在AIR应用程序中为iOS和Android播放MP3 [英] Play MP3 in AIR app for iOS and Android

查看:129
本文介绍了在AIR应用程序中为iOS和Android播放MP3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以阐明在为iOS和Android构建的AIR应用程序中嵌入,选择和播放音频文件的最佳方法?

I was wondering if someone could shed some light on the best method to embed, select and play audio files in an AIR app built for iOS and Android?

I有一个应用程序,用户可以在其中从10个音频文件的列表中选择要播放的文件。

I have an app where a user can select a file to play from a list of 10 audio files. These are selected when a slider moves left or right.

我目前将创建10个单独的嵌入代码段和类

I currently would create 10 individual embed snippets and classes

[Embed(source="assets/audio/file1.mp3)]
public static const file1:Class;

[Embed(source="assets/audio/file2.mp3)]
public static const file2:Class;
...

然后在应用程序中初始化每个类,以便我可以引用它们。然后只需调用

And then in the app initialise each class so I can reference them. Then simply call

file1.play();

问题是这只会播放一次声音,直到用户选择另一个声音为止声音。

Issue is this only plays the sound once where I would like the sound to look until the user selects another sound.

我猜几个问题:
1.拥有10个embed / classs是处理10个不同MP3文件的最佳方法吗?
2.我将如何无缝循环MP3

I guess a couple of questions: 1. Is having 10 embed/classes the best way to handle 10 different MP3 files? 2. How would I loop the MP3 seamlessly

谢谢

推荐答案

您存储了用户选择的Array或Vector mp3文件URL。并开始播放mp3。

You stored Array or Vector mp3 files URL which user selected. and playing mp3 filed ended. load next URL from Array, Vector.

var sound:Sound = new Sound();
var soundChannel:SoundChannel;
var currentIndex:int = 0;

var mp3List:Vector.<String> = new Vector.<String>();
//only stored user selected mp3 url

sound.addEventListener(Event.COMPLETE, onMp3LoadComplete);

sound.load(mp3List[currentIndex]);

function onMp3LoadComplete(e:Event):void
{
    sound.removeEventListener(Event.COMPLETE, onMp3LoadComplete);
    soundChannel = sound.play();
    soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}

function onSoundChannelSoundComplete(e:Event):void
{
    e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
    currentIndex++;
    if(currentIndex==mp3List.length) currentIndex = 0;
    sound.load(mp3List[currentIndex]);
    soundChannel = sound.play();
    sound.addEventListener(Event.COMPLETE, onMp3LoadComplete);
}

这篇关于在AIR应用程序中为iOS和Android播放MP3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆