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 /
avatar image
0
Question by teejayF · Oct 20, 2016 at 05:10 AM · androidunity 5screenshotnative pluginactivity

Android Unity, Screen Recording and MediaProjection APIs - UnityPlayerActivity hang.

I work on a project that uses MediaProjectionManager, MediaProjection and VirtualDisplay in order to record game play. This project also switches away from the UnityPlayerActivity and back every couple of minutes.

On the latest Unity, after starting my screen recording utility, I then switch to the UnityPlayerActivity:

  activity.finish();
 <Start Screen Recording>
  activity.startActivity({Intent starting the UnityPlayerActivity});
 <Call to UnitySendMessage triggering game scene to launch -> SceneManager.LoadScene(<scene name>)>

After doing this, the first time, the UnityPlayerActivity starts just fine, and my game switches from my native activity to my game scene and continues running. When game play finishes, I then switch back to my Native activity by calling static Java methods from UnityScript to trigger the change:

 unityPlayerActivity.startActivity(<nativeActivity>)

My activity then starts up just fine.

However, when I go to switch back to the UnityPlayerActivity a second time, it has hung. All rendering stops, and no messages I send it are received. This hang happens no matter which scene I try to trigger, whether or not I try to close out my screen recording utility, and whether or not I try to start my screen recording again on this second switch.

At this point, I've narrowed it down to the screen recording via trial and error removal of code, as no exceptions are thrown or logged. I'm fairly certain that the creation of the VirtualDisplay and MediaProjection are causing this issue.

     mMediaProjectionManager = (MediaProjectionManager) unityPlayerActivity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
     mMediaProjection = mMediaProjectionManager.getMediaProjection(mResultCode, mResultData);
     mVirtualDisplay = mMediaProjection.createVirtualDisplay(
             "recorder",
             mStream.getVideoQuality().resX,
             mStream.getVideoQuality().resY,
             DisplayMetrics.DENSITY_LOW,
             DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
             mSurface,
             null, // callback
             null  // handler
     );

Removing the creation of these from my screen recording utility clears up all of my problems, as does removing the screen recording utility entirely. This worked fine on Unity 4.x, but upon updating my project to 5.4, it's 100% reproducible.

Would anyone have any ideas on what could be going wrong, or how I could debug this issue?

Comment
Add comment · Show 1
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
avatar image AndreaSpace1 · Sep 20, 2018 at 02:45 PM 0
Share

Did you find a solution to your problem? I have a similar one and found out that the Unity application never receives the OnApplicationPause(true) message after giving permission for screen capture but I have no idea why this happens

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

NativePlugin c++ Android sample and self build pcl not loading,Native Plugins c++ "dll not found" 2 Answers

How to save screenshots on Android with Unity and C#? 0 Answers

How to save an in game screenshot directly to gallery? 1 Answer

Continue developing in Android Studio 1 Answer

Normal map is not working with Unity 5 when Low-level Native Plugin Interface is used 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