简体   繁体   English

如何将声音保存为铃声/通知?

[英]How to Save Sound as Ringtone/Notification?

Hey everyone so Not sure if this is possible using as3 for Android Air App. 嘿大家所以不确定这是否可以使用as3 for Android Air App。 I have been at it for a week now with some progress but not what I would want it to be. 我已经参加了一个星期,虽然取得了一些进展但不是我想要的。

So far I have it to where when the user swipes on the sound it brings up the storage location to save the sound on the phone. 到目前为止,我已经将它用于当用户滑动声音时它带出存储位置以将声音保存在手机上的位置。 Only problem is it doesn't let me save it as a ringtone or notification. 唯一的问题是它不允许我将其保存为铃声或通知。 Just saves it on the device; 只需将其保存在设备上;

I would like for the user to be able to click save and have it save to the ringtones for them to set it as the ringtone etc... 我希望用户能够点击保存并将其保存到铃声中,以便将其设置为铃声等...

Any help would be appreciated. 任何帮助,将不胜感激。 Here is what I have so far: 这是我到目前为止:

I am saving the sounds as wav. 我将声音保存为wav。 Still having some problems with this because once file is on the device and I try to play it, it plays it but then crashes and says can't read file. 仍有一些问题,因为一旦文件在设备上,我尝试播放它,它播放它,但然后崩溃,说无法读取文件。

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;
        }

As u can see I am using FileReference to save to device. 你可以看到我正在使用FileReference保存到设备。 But I know there has to be a way to save as ringtone. 但我知道必须有一种方法可以保存为铃声。 Thanks in advance. 提前致谢。

Only problem is it doesn't let me save it as a ringtone or notification. 唯一的问题是它不允许我将其保存为铃声或通知。 Just saves it on the device 只需将其保存在设备上即可

That's what FileReference does. 这就是FileReference功能。 load into your app or save into device storage. 加载到您的应用程序或保存到设备存储。
There is no built-in way in AS3 to set audio as an Android ringtone / notification. AS3中没有内置方式将音频设置为Android铃声/通知。 You might consider seeking out an ANE (Android Native Extension). 您可以考虑寻找ANE(Android原生扩展)。

I am saving the sounds as wav. 我将声音保存为wav。

Why put MP3 extension on a file with WAV (PCM) data? 为什么将MP3扩展名放在带有WAV(PCM)数据的文件上? See : f.save( wav, "Panda.Mp3" ); 见: f.save( wav, "Panda.Mp3" ); .

I try to play it, it plays it but then crashes and says can't read file. 我尝试播放它,它播放但然后崩溃,并说无法读取文件。

I don't know if this will fix your issue, but considering var snd:Sound = new sndPanda(); 我不知道这是否能解决你的问题,但考虑到var snd:Sound = new sndPanda(); ... ...
If sndPanda is MP3 data then use : 如果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" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM