【问题标题】:AS3 why Sound effect doesn't work on Android?AS3 为什么音效在 Android 上不起作用?
【发布时间】:2021-02-11 02:45:09
【问题描述】:

我使用 Adob​​e Animate 和 AS3 构建了一个相当简单的应用程序,它有许多按钮,当点击它们时会发出声音。运行应用程序测试时,声音效果很好。但在 Android 模拟器或 Android 设备上测试/调试应用时,声音不起作用。

名为“click.mp3”的声音文件已加载到 Animate 的库中。它有一个名为“Click”的类文件screenshot of the sound setting in Animate

这是我的代码示例。

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; //importing touch mode
import flash.events.TouchEvent;
import flash.display.Sprite; //importing sprite mode
import flash.text.TextFormat;

var mysound: Click = new Click(); // Sound mode

var sumButton: int; // Variable for Master Sum button 
var digiButton: int; // Variable for Master Digi Button
var masterArray: Array = new Array(); //Master array veriable
sumButton = 0;
digiButton = 0;

// Text Format for the sum buttons --------------------------------------------------------------------------
var newFormat: TextFormat = new TextFormat();
newFormat.size = 52;
newFormat.font = "Arial";
newFormat.align = "center";

//Sum Button 2 ------------------------------------------------
var square2: Sprite = new Sprite();
square2.graphics.beginFill(0x666666);
square2.graphics.drawRect(20, 190, 65, 65);
square2.graphics.endFill();
square2.buttonMode = true;
square2.addEventListener(TouchEvent.TOUCH_TAP, myTap2);

var myTF2: TextField = new TextField();
myTF2.x = 20;
myTF2.y = 190;
myTF2.width = 65;
myTF2.height = 65;
myTF2.border = true;
myTF2.borderColor = 0x10AD63;
myTF2.textColor = 0xFFFF99;
myTF2.wordWrap = false;
myTF2.appendText("2");
myTF2.setTextFormat(newFormat);

square2.addChild(myTF2);
this.addChild(square2);

function myTap2(event: TouchEvent): void {
    sumButton = 2;
    mysound.play();

}

下面是类“点击”代码的样子:

package  {
    
    import flash.media.Sound;
    
    
    public class Click extends Sound {
        
        
        public function Click() {
            // constructor code
        }
    }
    
}

为什么在 Android 上没有播放声音?

【问题讨论】:

标签: android actionscript-3 adobe adobe-animate


【解决方案1】:

解决方案是检查发布设置上的“覆盖声音设置”设置。

【讨论】:

    【解决方案2】:

    为避免使用覆盖声音设置,请将您的 MP3 变量声明为 Sound 数据类型。

    //# correct... play works as expected
    var mysound: Sound = new Click();
    
    //# wrong... play needs override to work 
    var mysound: Click = new Click(); 
    

    【讨论】:

    • 好吧,但很好奇,覆盖声音设置有什么问题?
    • 您的mysound 音频属于Sound 数据类型,所以如果您以后想使用声音没有问题,请保持这种状态(现在您很幸运,它可以工作)...如果您想要@ 987654325@ 为Click 数据类型,然后继续并覆盖其Sound 设置,因为也许您在Click 类中有您想要的代码或函数?保持音频为new Sound,代码为new Class
    • 我对@9​​87654331@ 进行了更改,但它在我的android 上不起作用,我仍然需要覆盖声音设置。
    • 这一切都非常很奇怪,因为 AFAIK 的“覆盖声音设置”只会影响音轨导出到生成的 SWF 中的方式。如果它打开,Flash 会将所有声音打包为指定质量的 MP3,而不考虑不同轨道自身的设置。我对问题的原因只有一个疯狂的想法:原始音轨采用某种奇怪的罕见格式/编解码器,Flash Player / PC 支持但 Android 不支持。
    猜你喜欢
    • 1970-01-01
    • 2015-03-15
    • 2021-07-13
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多