Commit a7584720 authored by JiangWanZhi's avatar JiangWanZhi

去掉了调用麦克风权限的问题

parent 72e7ed7f
...@@ -13,6 +13,8 @@ namespace NatSuite.Examples { ...@@ -13,6 +13,8 @@ namespace NatSuite.Examples {
using UnityEditor; using UnityEditor;
using UnityEngine.UI; using UnityEngine.UI;
using static UnityEngine.GraphicsBuffer; using static UnityEngine.GraphicsBuffer;
using UnityEngine.Rendering.Universal;
using System.IO;
public class ReplayCam : MonoBehaviour public class ReplayCam : MonoBehaviour
{ {
...@@ -45,26 +47,25 @@ namespace NatSuite.Examples { ...@@ -45,26 +47,25 @@ namespace NatSuite.Examples {
float val = 0; float val = 0;
private IEnumerator Start () { //private IEnumerator Start () {
// Start microphone // // Start microphone
microphoneSource = gameObject.AddComponent<AudioSource>(); // //microphoneSource = gameObject.AddComponent<AudioSource>();
microphoneSource.mute = // //microphoneSource.mute =
microphoneSource.loop = true; // //microphoneSource.loop = true;
microphoneSource.bypassEffects = // //microphoneSource.bypassEffects =
microphoneSource.bypassListenerEffects = false; // //microphoneSource.bypassListenerEffects = false;
if(recordMicrophone) // //if(recordMicrophone)
microphoneSource.clip = Microphone.Start(null, true, 10, AudioSettings.outputSampleRate); // // microphoneSource.clip = Microphone.Start(null, true, 10, AudioSettings.outputSampleRate);
yield return new WaitUntil(() => Microphone.GetPosition(null) > 0); // //yield return new WaitUntil(() => Microphone.GetPosition(null) > 0);
microphoneSource.Play(); // //microphoneSource.Play();
} //}
private void OnDestroy () { private void OnDestroy () {
// Stop microphone // Stop microphone
if (recordMicrophone) if (recordMicrophone)
{ {
microphoneSource.Stop(); //microphoneSource.Stop();
Microphone.End(null); //Microphone.End(null);
} }
} }
...@@ -103,14 +104,14 @@ namespace NatSuite.Examples { ...@@ -103,14 +104,14 @@ namespace NatSuite.Examples {
//audioInput = recordMicrophone ? new AudioInput(recorder, clock, microphoneSource, true) : null; //audioInput = recordMicrophone ? new AudioInput(recorder, clock, microphoneSource, true) : null;
audioInput = new AudioInput(recorder, clock, audioListener); audioInput = new AudioInput(recorder, clock, audioListener);
// Unmute microphone // Unmute microphone
microphoneSource.mute = true;// audioInput == null; //microphoneSource.mute = true;// audioInput == null;
} }
public void InterruptRecording() //停止录屏,但是不保存 public void InterruptRecording() //停止录屏,但是不保存
{ {
Debug.Log("停止录屏"); Debug.Log("停止录屏");
// Mute microphone // Mute microphone
microphoneSource.mute = true; //microphoneSource.mute = true;
// Stop recording // Stop recording
audioInput?.Dispose(); audioInput?.Dispose();
cameraInput?.Dispose(); cameraInput?.Dispose();
...@@ -122,14 +123,13 @@ namespace NatSuite.Examples { ...@@ -122,14 +123,13 @@ namespace NatSuite.Examples {
{ {
Debug.Log("结束录屏"); Debug.Log("结束录屏");
// Mute microphone // Mute microphone
microphoneSource.mute = true; //microphoneSource.mute = true;
// Stop recording // Stop recording
audioInput?.Dispose(); audioInput?.Dispose();
cameraInput?.Dispose(); cameraInput?.Dispose();
var path = await recorder.FinishWriting(); var path = await recorder.FinishWriting();
// Playback recording // Playback recording
Debug.Log($"Saved recording to: {path}"); Debug.Log($"Saved recording to: {path}");
var prefix = Application.platform == RuntimePlatform.IPhonePlayer ? "file://" : "";
#if UNITY_EDITOR #if UNITY_EDITOR
EditorUtility.OpenWithDefaultApp(path); EditorUtility.OpenWithDefaultApp(path);
...@@ -140,6 +140,51 @@ namespace NatSuite.Examples { ...@@ -140,6 +140,51 @@ namespace NatSuite.Examples {
#endif #endif
// 移动端,录频完后,播放录制的视频 // 移动端,录频完后,播放录制的视频
//Handheld.PlayFullScreenMovie($"{prefix}{path}"); //Handheld.PlayFullScreenMovie($"{prefix}{path}");
//OnReplay(path);
}
private void OnReplay(string path)
{
// 预览视频
#if UNITY_EDITOR
EditorUtility.OpenWithDefaultApp(path);
#elif UNITY_IOS
Handheld.PlayFullScreenMovie("file://" + path);
#elif UNITY_ANDROID
Handheld.PlayFullScreenMovie(path);
#endif
string destination = "";
string filename = path.Split('/')[path.Split('/').Length - 1];
if (Application.platform == RuntimePlatform.Android)
{
destination = "/sdcard/DCIM/电子手册";
if (!Directory.Exists(destination))
{
Directory.CreateDirectory(destination);
}
destination = destination + "/" + filename;
Debug.Log(destination);
File.Move(path, destination);
//// 安卓在这里需要去 调用原生的接口去 刷新一下,不然相册显示不出来
//using (AndroidJavaClass playerActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
//{
// using (AndroidJavaObject jo = playerActivity.GetStatic<AndroidJavaObject>("currentActivity"))
// {
// Debug.Log("scanFile:m_androidJavaObject ");
// jo.Call("scanFile", destination);
// }
//}
}
else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
#if UNITY_IOS
IOSAlbumCamera.iosSaveVideoToPhotosAlbum(path);
#endif
}
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment