Unity android Plugin MediaScan Question.,Android native plugin MediaScan Question
Please understand if translation does not work because I am using translator.
I'm currently looking for a way to do media scanning.
I've tried many ways listed in Google Search, but I can't solve them so I ask them.
using UnityEngine;
using NatCamU.Dispatch;
using FramePool = System.Collections.Generic.Dictionary<int, UnityEngine.RenderTexture>;
using System.IO;
public sealed class NatCorderAndroid : AndroidJavaProxy, INatCorder {
#region --Op vars--
private Configuration configuration;
private VideoCallback videoCallback;
private IAudioSource audioSource;
private MainDispatch dispatch;
private FramePool framePool = new FramePool();
private readonly AndroidJavaObject natcorder;
private readonly string filePath = "/mnt/sdcard/DCIM/Temp";
#endregion
#region --Properties--
public bool IsRecording { get { return natcorder.Call<bool>("isRecording"); }}
public bool Verbose { set { natcorder.Call("setVerboseMode", value); }}
#endregion
#region --Operations--
public NatCorderAndroid () : base("com.yusufolokoba.natcorder.NatCorderDelegate")
{
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
natcorder = new AndroidJavaObject("com.yusufolokoba.natcorder.NatCorder", this, filePath);
RenderDispatch.Initialize();
Debug.Log("NatCorder: Initialized NatCorder 1.2 Android backend");
}
public void StartRecording (Configuration configuration, VideoCallback videoCallback, IAudioSource audioSource)
{
// Make sure that recording size is multiple of two
configuration = new Configuration(2 * (configuration.width / 2), 2 * (configuration.height / 2), configuration.framerate, configuration.bitrate, configuration.keyframeInterval);
// Save state
this.dispatch = new MainDispatch();
this.configuration = configuration;
this.videoCallback = videoCallback;
this.audioSource = audioSource;
// Start recording
natcorder.Call("startRecording",
configuration.width,
configuration.height,
configuration.framerate,
configuration.bitrate,
configuration.keyframeInterval,
audioSource != null,
audioSource != null ? audioSource.sampleRate : 0,
audioSource != null ? audioSource.sampleCount : 0,
audioSource != null ? audioSource.channelCount : 0
);
}
public void StopRecording () {
if (audioSource != null) audioSource.Dispose();
audioSource = null;
natcorder.Call("stopRecording");
}
public Frame AcquireFrame () {
return new Frame(
RenderTexture.GetTemporary(
configuration.width,
configuration.height,
24,
RenderTextureFormat.Default,
RenderTextureReadWrite.Default,
1
)
);
}
public void CommitFrame (Frame frame)
{
var handle = ((RenderTexture)frame).GetNativeTexturePtr().ToInt32();
framePool.Add(handle, frame);
natcorder.Call("encodeFrame", handle, frame.timestamp);
}
public void CommitSamples (float[] sampleBuffer, long timestamp) {
AndroidJNI.AttachCurrentThread();
natcorder.Call("encodeSamples", sampleBuffer, timestamp);
}
#endregion
#region --Callbacks--
private void onEncode (int frame) {
dispatch.Dispatch(() => {
// Release RenderTexture
var surface = framePool[frame];
RenderTexture.ReleaseTemporary(surface);
framePool.Remove(frame);
});
}
private void onVideo (string path) {
dispatch.Dispatch(() => videoCallback(path));
dispatch.Dispose();
dispatch = null;
}
#endregion
}
I am currently using an asset called Natcorder.
//private readonly string filePath = "/mnt/sdcard/DCIM/Temp"; and
// if (!Directory.Exists(filePath)) // Directory.CreateDirectory(filePath); // natcorder = new AndroidJavaObject("com.yusufolokoba.natcorder.NatCorder", this, filePath);
We modified this part to confirm that the folder creation and recorded images are well created in the folder.
However, the gallery does not renew.
They have created and run a plug-in, but it is not recorded either.
AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject objActivity = classPlayer.GetStatic("currentActivity");
Debug.Log("**create Uri class"); AndroidJavaClass classUri = new AndroidJavaClass("android.net.Uri");
Debug.Log("**create Intent object"); AndroidJavaObject objIntent = new AndroidJavaObject("android.content.Intent", new object[2]{"android.intent.action.MEDIA_MOUNTED", classUri.CallStatic("parse", "file:///mnt/sdcard/TestFolder/SubFolder/" + filename)});
Debug.Log("**call sendBroadcast"); objActivity.Call ("sendBroadcast", objIntent);
I've used this code, but it doesn't work.
I would appreciate it if you could let me know if anyone found a problem like me and solved it. I beg you.,
Your answer

Follow this Question
Related Questions
FitnessSensorService not being started by Android OS 1 Answer
CommandInvokationFailure: Failed to re-package resources Mapbox/FB 0 Answers
Unity plug-in/ Support SDK or 3rd party plug-in to handle Huawei Dynamic ability SDK. 0 Answers
problem on rendertexture handling on Android 0 Answers
Unity APK doesn't load on Android. 0 Answers