Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Lee-Jung-Min · Jul 27, 2018 at 11:17 AM · androidplugin

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.,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

150 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges