Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
tuseGameColor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shujianhe
tuseGameColor
Commits
a7584720
Commit
a7584720
authored
Aug 25, 2023
by
JiangWanZhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去掉了调用麦克风权限的问题
parent
72e7ed7f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
19 deletions
+64
-19
ReplayCam.cs
Assets/NatCorder/Examples/ReplayCam/ReplayCam.cs
+64
-19
No files found.
Assets/NatCorder/Examples/ReplayCam/ReplayCam.cs
View file @
a7584720
...
...
@@ -13,6 +13,8 @@ namespace NatSuite.Examples {
using
UnityEditor
;
using
UnityEngine.UI
;
using
static
UnityEngine
.
GraphicsBuffer
;
using
UnityEngine.Rendering.Universal
;
using
System.IO
;
public
class
ReplayCam
:
MonoBehaviour
{
...
...
@@ -45,26 +47,25 @@ namespace NatSuite.Examples {
float
val
=
0
;
private
IEnumerator
Start
()
{
// Start microphone
microphoneSource
=
gameObject
.
AddComponent
<
AudioSource
>();
microphoneSource
.
mute
=
microphoneSource
.
loop
=
true
;
microphoneSource
.
bypassEffects
=
microphoneSource
.
bypassListenerEffects
=
false
;
if
(
recordMicrophone
)
microphoneSource
.
clip
=
Microphone
.
Start
(
null
,
true
,
10
,
AudioSettings
.
outputSampleRate
);
yield
return
new
WaitUntil
(()
=>
Microphone
.
GetPosition
(
null
)
>
0
);
microphoneSource
.
Play
();
}
//
private IEnumerator Start () {
//
// Start microphone
// //
microphoneSource = gameObject.AddComponent<AudioSource>();
// //
microphoneSource.mute =
// //
microphoneSource.loop = true;
// //
microphoneSource.bypassEffects =
// //
microphoneSource.bypassListenerEffects = false;
// //
if(recordMicrophone)
// //
microphoneSource.clip = Microphone.Start(null, true, 10, AudioSettings.outputSampleRate);
// //
yield return new WaitUntil(() => Microphone.GetPosition(null) > 0);
// //
microphoneSource.Play();
//
}
private
void
OnDestroy
()
{
// Stop microphone
if
(
recordMicrophone
)
{
microphoneSource
.
Stop
();
Microphone
.
End
(
null
);
//microphoneSource.Stop();
//Microphone.End(null);
}
}
...
...
@@ -103,14 +104,14 @@ namespace NatSuite.Examples {
//audioInput = recordMicrophone ? new AudioInput(recorder, clock, microphoneSource, true) : null;
audioInput
=
new
AudioInput
(
recorder
,
clock
,
audioListener
);
// Unmute microphone
microphoneSource
.
mute
=
true
;
// audioInput == null;
//
microphoneSource.mute = true;// audioInput == null;
}
public
void
InterruptRecording
()
//停止录屏,但是不保存
{
Debug
.
Log
(
"停止录屏"
);
// Mute microphone
microphoneSource
.
mute
=
true
;
//
microphoneSource.mute = true;
// Stop recording
audioInput
?.
Dispose
();
cameraInput
?.
Dispose
();
...
...
@@ -122,14 +123,13 @@ namespace NatSuite.Examples {
{
Debug
.
Log
(
"结束录屏"
);
// Mute microphone
microphoneSource
.
mute
=
true
;
//
microphoneSource.mute = true;
// Stop recording
audioInput
?.
Dispose
();
cameraInput
?.
Dispose
();
var
path
=
await
recorder
.
FinishWriting
();
// Playback recording
Debug
.
Log
(
$"Saved recording to:
{
path
}
"
);
var
prefix
=
Application
.
platform
==
RuntimePlatform
.
IPhonePlayer
?
"file://"
:
""
;
#if UNITY_EDITOR
EditorUtility
.
OpenWithDefaultApp
(
path
);
...
...
@@ -140,6 +140,51 @@ namespace NatSuite.Examples {
#endif
// 移动端,录频完后,播放录制的视频
//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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment