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 mechwarr · Mar 07, 2016 at 04:11 PM · c#androidplugin

Unity plugin call android Activity implements TextureView.SurfaceTextureListener!

I need add mirrored video midea player in Unity plugin from Android project.

So , I use TextureView to show my mp4 file , and I have build Android native project success work in my android device.

But , when I build a jar file import to my unity project , run the application will crash.

This is my Android code "mirrored video.class" :

         import android.app.Activity;
         import android.content.pm.ActivityInfo;
         import android.graphics.SurfaceTexture;
         import android.media.AudioManager;
         import android.os.Bundle;
         import android.util.Log;
         import android.view.MenuItem;
         import android.view.Surface;
         import android.view.TextureView;
 
 public class mirroredvideo extends Activity implements TextureView.SurfaceTextureListener{
 
     boolean isMirrored = true;
     public CustomMediaPlayer customMediaPlayer;
     public String video_url = null;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         try
         {
             int layoutID = getResources().getIdentifier("activity_mirroredvideo", "layout", getPackageName());
             int textureViewID = getResources().getIdentifier("mirrored_textureView", "id", getPackageName());
             setContentView(layoutID);
             //video_url = this.getIntent().getStringExtra("VURL"); // your URL here
             video_url = "http://devstreaming.apple.com/videos/wwdc/2015/217wu453thu1r1/217/217_hd_adopting_new_trackpad_features.mp4";
             customMediaPlayer = new CustomMediaPlayer ();
             TextureView textureView = (TextureView)findViewById(textureViewID);
             textureView.setSurfaceTextureListener(this);
             textureView.setScaleX(isMirrored ? -1 : 1);
         }catch (Error e)
         {
             Log.v("mirroredvideo","catch error : "+e);
         }
 
 
     }
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         return super.onOptionsItemSelected(item);
     }
 
 
     @Override
     public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
 
         try {
             customMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
             customMediaPlayer.setSurface(new Surface(surface));
             customMediaPlayer.setDataSource(video_url);
             customMediaPlayer.prepare(); // might take long! (for buffering, etc)
             customMediaPlayer.start();
 
             if(customMediaPlayer.isPlaying())
             {
                 Log.v("customMediaPlayer:","customMediaPlayer really start..");
             }
 
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
     @Override
     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
 
     }
 
     @Override
     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
         return false;
     }
 
     @Override
     public void onSurfaceTextureUpdated(SurfaceTexture surface) {
 
     }
 
     @Override
     protected void onPause() {
         super.onPause();
         customMediaPlayer.pause();
     }
 
     @Override
     protected void onDestroy() {
         super.onDestroy();
         customMediaPlayer.stop();
     }
 
     @Override
     protected void onRestart() {
         super.onRestart();
         customMediaPlayer.start();
     }
 
     @Override
     protected void onResume() {
         if(getRequestedOrientation()!= ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
             setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
         }
         super.onResume();
     }
 
 }

And I create a class "CustomMediaPlayer.class" :

 import android.media.MediaPlayer;
 
 import java.io.IOException;
 
 /**
  * Created by playar on 2016/2/24.
  */
 class CustomMediaPlayer extends MediaPlayer
 {
     String dataSource;
 
     @Override
     public void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException
     {
         // TODO Auto-generated method stub
         super.setDataSource(path);
         dataSource = path;
     }
 
     public String getDataSource()
     {
         return dataSource;
     }
 }

Then , this is my request and response with Unity class "requestUnity.class" :

 public class requestUnity extends UnityPlayerActivity{
 
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
     }
 
 
     public static void videomirrored(Activity gactivity) {
         Intent intent = new Intent(gactivity, mirroredvideo.class);
         gactivity.startActivity(intent);
     }
 }

Finally , this is my unity C# script code :

         using (AndroidJavaClass androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
         { 
             using(AndroidJavaObject jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity"))
             {
                 using(AndroidJavaClass jc = new AndroidJavaClass("com.xxx.xxx.requestUnity"))
                 {
                     jc.CallStatic("videomirrored", jo);
                 }
             }
         } 


There is my crash log when I run this application : alt text

And I have find the application can't run to onSurfaceTextureAvailable function! (If in the native code project , it's nice work for me.) Did anyone can help me this problem ?

螢幕快照-2016-03-06-上午103722.png (247.9 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mechwarr · Mar 11, 2016 at 03:18 AM

Have anyone help me!! please~~

Comment
Add comment · Share
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

AndroidJavaClass Call non-static method from Jar to return String with CallLog 1 Answer

How can I use SQLite Database made with android studio in Unity? 0 Answers

Admob unity 2017.3 compile error 0 Answers

How turn On/Off android display backlight using C# only in Unity3d 1 Answer

Help with google vr for android api 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