首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在AS3安卓应用程序中添加音乐

如何在AS3安卓应用程序中添加音乐
EN

Stack Overflow用户
提问于 2015-03-04 05:46:24
回答 1查看 397关注 0票数 0

我是3中的菜鸟。

我想要一个AS3中的音乐播放器(带有开始、暂停按钮)代码,我已经在库中导入了音乐,并添加了以下代码

代码语言:javascript
运行
复制
var qMySound:Sound = new mySound1();
qMySound.play(0, 9999);

mySound1是AS链接,它可以工作。

我用代码片段的代码做了一个停止按钮

代码语言:javascript
运行
复制
button_7.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds_6);

function fl_ClickToStopAllSounds_6(event:MouseEvent):void
{
    SoundMixer.stopAll();
}

它也能工作,但是现在我想再次启动它,我尝试使用以下代码:

代码语言:javascript
运行
复制
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_28);

function fl_ClickToGoToAndStopAtFrame_28(event:MouseEvent):void
{
    gotoAndStop(1);
}

音乐AS3代码在帧1字节内。

这不管用..。有什么想法吗?

编辑:这是我的代码:

代码语言:javascript
运行
复制
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
var lastPosition:Number = 0;
var mySound:Sound = new mySound1(0,999);
myChannel = mySound.play();
// here is to learn how to deal with volume as well (between 0 and 1)
myTransform.volume = .5;
// setting the SoundTransform instance to the myChannel object
myChannel.soundTransform = myTransform;

pause_btn.addEventListener(MouseEvent.CLICK, onClickPauseHandler, false, 0, true);
play_btn.addEventListener(MouseEvent.CLICK, onClickPlayHandler, false, 0, true);

function onClickPauseHandler(event:MouseEvent):void
{
    // getting the current position of the sound
    lastPosition = myChannel.position;
    // stopping the current sound
    myChannel.stop();
}

function onClickPlayHandler(event:MouseEvent):void
{
    // playing from the saved position
    myChannel = mySound.play(0,999);
}

这个错误就会冒出来。

第8行:在名称空间内部,与mySound的定义存在冲突。

EN

回答 1

Stack Overflow用户

发布于 2015-03-04 07:25:17

您需要使用类SoundChannel/SoundTransform来具有更多的功能。当您使用SoundMixer.stopAll()停止所有声音时,并不是要停止相应的声音。

遵循一些示例代码,您可以指导您实现您所期望的目标,另外,还要提供一些关于如何处理声音的额外知识。

代码语言:javascript
运行
复制
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var myTransform:SoundTransform = new SoundTransform();
var lastPosition:Number = 0;
mySound.load(new URLRequest('yourMp3FileName.mp3'));
myChannel = mySound.play();
// here is to learn how to deal with volume as well (between 0 and 1)
myTransform.volume = .5;
// setting the SoundTransform instance to the myChannel object
myChannel.soundTransform = myTransform;

pause_btn.addEventListener(MouseEvent.CLICK, onClickPauseHandler, false, 0, true);
play_btn.addEventListener(MouseEvent.CLICK, onClickPlayHandler, false, 0, true);

function onClickPauseHandler(event:MouseEvent):void
{
    // getting the current position of the sound
    lastPosition = myChannel.position;
    // stopping the current sound
    myChannel.stop();
}

function onClickPlayHandler(event:MouseEvent):void
{
    // playing from the saved position
    myChannel = mySound.play(lastPosition);
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28847417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档