大家好,不确定是否可以将 as3 用于 Android Air 应用程序。我已经做了一个星期,取得了一些进展,但不是我想要的。
到目前为止,当用户在声音上滑动时,它会调出存储位置以将声音保存在手机上。唯一的问题是它不允许我将它保存为铃声或通知。只需将其保存在设备上即可;
我希望用户能够单击保存并将其保存到铃声中,以便他们将其设置为铃声等...
如有任何帮助,我们将不胜感激。这是我目前所拥有的:
我正在将声音保存为 wav。这仍然有一些问题,因为一旦文件在设备上并且我尝试播放它,它播放它但然后崩溃并说无法读取文件。
var snd:Sound = new sndPanda();
var sndBytes:ByteArray = new ByteArray();
sndBytes.endian = Endian.LITTLE_ENDIAN;
snd.extract( sndBytes, 44100 * 2 );
var wav:ByteArray = encode( sndBytes );
var f:FileReference = new FileReference(); //save file to phone
f.save( wav, "Panda.Mp3" );
function encode( data:ByteArray ):ByteArray
{
var channels:uint = 2;
var bits:uint = 16;
var rate:uint = 44100;
var bytes: ByteArray = new ByteArray();
bytes.endian = Endian.LITTLE_ENDIAN;
bytes.writeUTFBytes( 'RIFF' );
bytes.writeInt( uint( data.length + 44 ) );
bytes.writeUTFBytes( 'WAVE' );
bytes.writeUTFBytes( 'fmt ' );
bytes.writeInt( uint( 16 ) );
bytes.writeShort( uint( 1 ) );
bytes.writeShort( channels );
bytes.writeInt( rate );
bytes.writeInt( uint( rate * channels * ( bits / 8 ) ) );
bytes.writeShort( uint( channels * ( bits / 8 ) ) );
bytes.writeShort( bits );
bytes.writeUTFBytes( 'data' );
bytes.writeInt( data.length );
data.position = 0;
var length:int = data.length - 4;
while (data.position < length) { // could be better :-)
bytes.writeShort(uint(data.readFloat() * 65536));
}
bytes.position = 0;
return bytes;
}
如您所见,我正在使用 FileReference 保存到设备。但我知道必须有一种方法可以保存为铃声。提前致谢。
最佳答案
Only problem is it doesn't let me save it as a ringtone or notification. Just saves it on the device
这就是 FileReference
所做的。 加载到您的应用程序或保存到设备存储。
AS3 中没有内置方法可以将音频设置为 Android 铃声/通知。您可能会考虑寻找 ANE(Android native 扩展)。
I am saving the sounds as wav.
为什么将 MP3 扩展名放在带有 WAV (PCM) 数据的文件上?参见:f.save(wav, "Panda.Mp3");
。
I try to play it, it plays it but then crashes and says can't read file.
我不知道这是否能解决您的问题,但考虑到 var snd:Sound = new sndPanda();
...
如果 sndPanda
是 MP3 数据,那么使用:
var snd:Sound = new sndPanda();
var sndBytes:ByteArray = new ByteArray();
var totalSamples : int = int( Math.floor ( (snd.length/1000) * 44100) );
sndBytes.endian = Endian.LITTLE_ENDIAN;
snd.extract( sndBytes, totalSamples );
var wav:ByteArray = encode( sndBytes );
var f:FileReference = new FileReference(); //save file to phone
f.save( wav, "Panda.Mp3" );
关于android - 如何将声音保存为铃声/通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38176001/