【发布时间】:2018-08-04 03:10:28
【问题描述】:
我正在开发一项应用功能,以便能够将我在应用中的声音传递给 whatsapp。我已经取得了一些进展,但我一直坚持获取 AudioClip 的字节数组。
所以我需要从资源文件夹中获取音频剪辑并将其写入我给的路径,然后将其发送到whatsapp。
这会出错
FormatException:长度无效。 System.Convert.FromBase64String (System.String s) (在 /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:146)
void sendProccess()
{
string s = Resources.Load<AudioClip>("Bava").ToString();
byte[] dataToSave = System.Convert.FromBase64String(s);
string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".mp3");
File.WriteAllBytes(destination, dataToSave);
if (!Application.isEditor)
{
//instantiate the class Intent
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
//instantiate the class Uri
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + destination);
//call putExtra with the uri object of the file
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("setType", "audio/mp3");
//instantiate the class UnityPlayer
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
//instantiate the object currentActivity
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
//call the activity with our Intent
currentActivity.Call("startActivity", intentObject);
}
}
提前致谢。
【问题讨论】:
-
所以...您的问题是
How to convert audio into Base64?。还要将您的代码放入问题中,而不是图像。 -
是的,这就是我遇到困难的部分,我添加了代码,对不起,我是新人。