55using UnityEngine ;
66
77public class ExoPlayerUnityPlugin : MonoBehaviour {
8- public String mediaUri = "" ;
8+ public String [ ] mediaUri ;
9+ public int uriIdx = 0 ;
910 bool startedVideo ;
1011 IntPtr nativeTexturePtr = IntPtr . Zero ;
1112 int nativeTextureWidth = 0 ;
@@ -28,6 +29,12 @@ private enum EventType {
2829 [ DllImport ( "ExoPlayerUnityPlugin" ) ]
2930 private static extern IntPtr exoPlayerUnityPlugin_renderEvent ( ) ;
3031
32+ [ DllImport ( "ExoPlayerUnityPlugin" ) ]
33+ private static extern void exoPlayerUnityPlugin_play ( ) ;
34+
35+ [ DllImport ( "ExoPlayerUnityPlugin" ) ]
36+ private static extern void exoPlayerUnityPlugin_pause ( ) ;
37+
3138 void Awake ( ) {
3239 Renderer mediaRenderer = GetComponent < Renderer > ( ) ;
3340
@@ -61,7 +68,7 @@ IEnumerator DelayedStartVideo() {
6168 object [ ] args = { ( int ) nativeTexturePtr } ;
6269
6370 LOG . CallStatic < int > ( "d" , "EXOPLUGIN-Unity" , "Start | JNI setUri" ) ;
64- exoPlayerUnityPlugin_setUri ( mediaUri ) ;
71+ exoPlayerUnityPlugin_setUri ( mediaUri [ uriIdx ] ) ;
6572 LOG . CallStatic < int > ( "d" , "EXOPLUGIN-Unity" , "Start | JNI setupPlayer" ) ;
6673 exoPlayerUnityPlugin_setupPlayer ( ( int ) nativeTexturePtr ) ;
6774 }
@@ -73,7 +80,36 @@ void Update() {
7380 GL . InvalidateState ( ) ;
7481 }
7582
83+ private void OnApplicationPause ( ) {
84+ exoPlayerUnityPlugin_pause ( ) ;
85+ }
86+
7687 private void OnApplicationQuit ( ) {
7788 GL . IssuePluginEvent ( exoPlayerUnityPlugin_renderEvent ( ) , ( int ) EventType . Release ) ;
7889 }
90+
91+ public void PlayerPlay ( ) {
92+ LOG . CallStatic < int > ( "d" , "EXOPLUGIN-Unity" , "OnClick | JNI Play" ) ;
93+ try {
94+ exoPlayerUnityPlugin_play ( ) ;
95+ } catch ( Exception e ) {
96+ LOG . CallStatic < int > ( "w" , "EXOPLUGIN-Unity" , $ "Failed to play: { e . Message } \n { e . StackTrace } ") ;
97+ }
98+ }
99+
100+ public void PlayerPause ( ) {
101+ LOG . CallStatic < int > ( "d" , "EXOPLUGIN-Unity" , "OnClick | JNI Pause" ) ;
102+ try {
103+ exoPlayerUnityPlugin_pause ( ) ;
104+ } catch ( Exception e ) {
105+ LOG . CallStatic < int > ( "w" , "EXOPLUGIN-Unity" , $ "Failed to pause: { e . Message } \n { e . StackTrace } ") ;
106+ }
107+
108+ }
109+
110+ public void CycleUri ( ) {
111+ LOG . CallStatic < int > ( "d" , "EXOPLUGIN-Unity" , "OnClick | JNI Next URI" ) ;
112+ uriIdx = ( uriIdx + 1 ) % mediaUri . Length ;
113+ exoPlayerUnityPlugin_setUri ( mediaUri [ uriIdx ] ) ;
114+ }
79115}
0 commit comments