123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725 |
- #if (UNITY_EDITOR || UNITY_ANDROID)
- #define AVPROVIDEO_FIXREGRESSION_TEXTUREQUALITY_UNITY542
- #define DLL_METHODS
- using UnityEngine;
- using System;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace RenderHeads.Media.AVProVideo
- {
-
-
-
-
- public class AndroidMediaPlayer : BaseMediaPlayer
- {
- protected static AndroidJavaObject s_ActivityContext = null;
- protected static AndroidJavaObject s_Interface = null;
- protected static bool s_bInitialised = false;
- private static string s_Version = "Plug-in not yet initialised";
- private static System.IntPtr _nativeFunction_RenderEvent = System.IntPtr.Zero;
- protected AndroidJavaObject m_Video;
- private Texture2D m_Texture;
- private int m_TextureHandle;
- private bool m_UseFastOesPath;
- private double m_Duration = 0.0;
- private int m_Width = 0;
- private int m_Height = 0;
- protected int m_iPlayerIndex = -1;
- private Android.VideoApi m_API;
- private bool m_HeadRotationEnabled = false;
- private bool m_FocusEnabled = false;
- private System.IntPtr m_Method_Update;
- private System.IntPtr m_Method_SetHeadRotation;
- private System.IntPtr m_Method_GetCurrentTimeS;
- private System.IntPtr m_Method_GetSourceVideoFrameRate;
- private System.IntPtr m_Method_IsPlaying;
- private System.IntPtr m_Method_IsPaused;
- private System.IntPtr m_Method_IsFinished;
- private System.IntPtr m_Method_IsSeeking;
- private System.IntPtr m_Method_IsBuffering;
- private System.IntPtr m_Method_IsLooping;
- private System.IntPtr m_Method_HasVideo;
- private System.IntPtr m_Method_HasAudio;
- private System.IntPtr m_Method_HasMetaData;
- private System.IntPtr m_Method_SetFocusProps;
- private System.IntPtr m_Method_SetFocusEnabled;
- private System.IntPtr m_Method_SetFocusRotation;
- private jvalue[] m_Value0 = new jvalue[0];
- private jvalue[] m_Value1 = new jvalue[1];
- private jvalue[] m_Value2 = new jvalue[2];
- private jvalue[] m_Value4 = new jvalue[4];
- private MediaPlayer.OptionsAndroid m_Options;
- private enum NativeStereoPacking : int
- {
- Unknown = -1,
- Monoscopic = 0,
- TopBottom = 1,
- LeftRight = 2,
- Mesh = 3,
- }
- #if AVPROVIDEO_FIXREGRESSION_TEXTUREQUALITY_UNITY542
- #if UNITY_2022_2_OR_NEWER
-
- private int _textureQuality = QualitySettings.globalTextureMipmapLimit;
- #else
- private int _textureQuality = QualitySettings.masterTextureLimit;
- #endif
- #endif
- static private System.Threading.Thread m_MainThread;
- public static bool InitialisePlatform()
- {
- m_MainThread = System.Threading.Thread.CurrentThread;
-
- if (s_ActivityContext == null)
- {
- AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- if (activityClass != null)
- {
- s_ActivityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
- }
- }
- if (!s_bInitialised)
- {
- s_Interface = new AndroidJavaObject("com.renderheads.AVPro.Video.Manager");
- if (s_Interface != null)
- {
- s_Version = s_Interface.Call<string>("GetPluginVersion");
- s_Interface.Call("SetContext", s_ActivityContext);
-
-
- _nativeFunction_RenderEvent = Native.GetRenderEventFunc();
- if (_nativeFunction_RenderEvent != IntPtr.Zero)
- {
- s_bInitialised = true;
- }
- }
- }
- return s_bInitialised;
- }
- public static void DeinitPlatform()
- {
- if (s_bInitialised)
- {
- if (s_Interface != null)
- {
- s_Interface.CallStatic("Deinitialise");
- s_Interface = null;
- }
- s_ActivityContext = null;
- s_bInitialised = false;
- }
- }
- private static void IssuePluginEvent(Native.AVPPluginEvent type, int param)
- {
-
- int eventId = 0x5d5ac000 | ((int)type << 8);
- switch (type)
- {
- case Native.AVPPluginEvent.PlayerSetup:
- case Native.AVPPluginEvent.PlayerUpdate:
- case Native.AVPPluginEvent.PlayerDestroy:
- case Native.AVPPluginEvent.ExtractFrame:
- {
- eventId |= param & 0xff;
- }
- break;
- }
- GL.IssuePluginEvent(_nativeFunction_RenderEvent, eventId);
- }
- private System.IntPtr GetMethod(string methodName, string signature)
- {
- Debug.Assert(m_Video != null);
- System.IntPtr result = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), methodName, signature, false);
- Debug.Assert(result != System.IntPtr.Zero);
- if (result == System.IntPtr.Zero)
- {
- Debug.LogError("[AVProVideo] Unable to get method " + methodName + " " + signature);
- throw new System.Exception("[AVProVideo] Unable to get method " + methodName + " " + signature);
- }
- return result;
- }
- public AndroidMediaPlayer(MediaPlayer.OptionsAndroid options) : base()
- {
- Debug.Assert(s_Interface != null);
- Debug.Assert(s_bInitialised);
- m_Options = options;
- m_API = options.videoApi;
- if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Vulkan)
- {
- Debug.LogWarning("[AVProVideo] Vulkan graphics API is not supported. Please select OpenGL ES 2.0 and 3.0 are supported on Android.");
- }
- #if UNITY_2017_2_OR_NEWER
- Vector2 vPreferredVideo = GetPreferredVideoResolution(options.preferredMaximumResolution, options.customPreferredMaximumResolution);
- #else
- Vector2 vPreferredVideo = GetPreferredVideoResolution(options.preferredMaximumResolution, new Vector2(0.0f, 0.0f));
- #endif
-
- Debug.Log("s_Interface " + s_Interface);
- m_Video = s_Interface.Call<AndroidJavaObject>( "CreatePlayer", (int)(m_API), options.useFastOesPath, options.preferSoftwareDecoder, (int)(options.audioOutput), (int)(options.audio360ChannelMode), Helper.GetUnityAudioSampleRate(),
- options.StartWithHighestBandwidth(), options.minBufferMs, options.maxBufferMs, options.bufferForPlaybackMs, options.bufferForPlaybackAfterRebufferMs,
- (int)(options.GetPreferredPeakBitRateInBitsPerSecond()), (int)(vPreferredVideo.x), (int)(vPreferredVideo.y), (int)(options.blitTextureFiltering) );
- Debug.Log("m_Video " + m_Video);
- if (m_Video != null)
- {
- m_Method_Update = GetMethod("Update", "()V");
- m_Method_SetHeadRotation = GetMethod("SetHeadRotation", "(FFFF)V");
- m_Method_SetFocusProps = GetMethod("SetFocusProps", "(FF)V");
- m_Method_SetFocusEnabled = GetMethod("SetFocusEnabled", "(Z)V");
- m_Method_SetFocusRotation = GetMethod("SetFocusRotation", "(FFFF)V");
- m_Method_GetCurrentTimeS = GetMethod("GetCurrentTimeS", "()D");
- m_Method_GetSourceVideoFrameRate = GetMethod("GetSourceVideoFrameRate", "()F");
- m_Method_IsPlaying = GetMethod("IsPlaying", "()Z");
- m_Method_IsPaused = GetMethod("IsPaused", "()Z");
- m_Method_IsFinished = GetMethod("IsFinished", "()Z");
- m_Method_IsSeeking = GetMethod("IsSeeking", "()Z");
- m_Method_IsBuffering = GetMethod("IsBuffering", "()Z");
- m_Method_IsLooping = GetMethod("IsLooping", "()Z");
- m_Method_HasVideo = GetMethod("HasVideo", "()Z");
- m_Method_HasAudio = GetMethod("HasAudio", "()Z");
- m_Method_HasMetaData = GetMethod("HasMetaData", "()Z");
- m_iPlayerIndex = m_Video.Call<int>("GetPlayerIndex");
- Helper.LogInfo("Creating player " + m_iPlayerIndex);
- SetOptions(options.useFastOesPath, options.showPosterFrame);
-
- AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerSetup, m_iPlayerIndex);
- }
- else
- {
- Debug.LogError("[AVProVideo] Failed to create player instance");
- }
- }
- public void SetOptions(bool useFastOesPath, bool showPosterFrame)
- {
- m_UseFastOesPath = useFastOesPath;
- if (m_Video != null)
- {
-
- showPosterFrame = (m_API == Android.VideoApi.MediaPlayer) ? showPosterFrame:false;
- m_Video.Call("SetPlayerOptions", m_UseFastOesPath, showPosterFrame);
- }
- }
- public override long GetEstimatedTotalBandwidthUsed()
- {
- long result = -1;
- if (s_Interface != null)
- {
- result = m_Video.Call<long>("GetEstimatedBandwidthUsed");
- }
- return result;
- }
- public override string GetVersion()
- {
- return s_Version;
- }
- public override string GetExpectedVersion()
- {
- return Helper.ExpectedPluginVersion.Android;
- }
- public override bool OpenMedia(string path, long offset, string httpHeader, MediaHints mediaHints, int forceFileFormat = 0, bool startWithHighestBitrate = false)
- {
- bool bReturn = false;
- if (m_Video != null)
- {
- _mediaHints = mediaHints;
- Debug.Assert(m_Width == 0 && m_Height == 0 && m_Duration == 0.0);
- bReturn = m_Video.Call<bool>("OpenVideoFromFile", path, offset, httpHeader, forceFileFormat, (int)(m_Options.audioOutput), (int)(m_Options.audio360ChannelMode));
- if (!bReturn)
- {
- DisplayLoadFailureSuggestion(path);
- }
- }
- else
- {
- Debug.LogError("[AVProVideo] m_Video is null!");
- }
- return bReturn;
- }
- public override void SetKeyServerAuthToken(string token)
- {
- if (m_Video != null)
- {
- m_Video.Call("SetKeyServerAuthToken", token);
- }
- }
- public override void SetOverrideDecryptionKey(byte[] key)
- {
- if( m_Video != null )
- {
- m_Video.Call("SetOverrideDecryptionKey", key);
- }
- }
- private void DisplayLoadFailureSuggestion(string path)
- {
- if (path.ToLower().Contains("http://"))
- {
- Debug.LogError("Android 8 and above require HTTPS by default, change to HTTPS or enable ClearText in the AndroidManifest.xml");
- }
- }
- public override void CloseMedia()
- {
- if (m_Texture != null)
- {
- Texture2D.Destroy(m_Texture);
- m_Texture = null;
- }
- m_TextureHandle = 0;
- m_Duration = 0.0;
- m_Width = 0;
- m_Height = 0;
- if (m_Video != null)
- {
- m_Video.Call("CloseVideo");
- }
- base.CloseMedia();
- }
- public override void SetLooping( bool bLooping )
- {
- if( m_Video != null )
- {
- m_Video.Call("SetLooping", bLooping);
- }
- }
- public override bool IsLooping()
- {
- bool result = false;
- if( m_Video != null )
- {
- if (m_Method_IsLooping != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsLooping, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsLooping");
- }
- }
- return result;
- }
- public override bool HasVideo()
- {
- bool result = false;
- if( m_Video != null )
- {
- if (m_Method_HasVideo != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_HasVideo, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("HasVideo");
- }
- }
- return result;
- }
- public override bool HasAudio()
- {
- bool result = false;
- if( m_Video != null )
- {
- if (m_Method_HasAudio != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_HasAudio, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("HasAudio");
- }
- }
- return result;
- }
- public override bool HasMetaData()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_HasMetaData != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_HasMetaData, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("HasMetaData");
- }
- }
- return result;
- }
- public override bool CanPlay()
- {
- bool result = false;
- #if DLL_METHODS
- result = Native._CanPlay( m_iPlayerIndex );
- #else
- if (m_Video != null)
- {
- result = m_Video.Call<bool>("CanPlay");
- }
- #endif
- return result;
- }
- public override void Play()
- {
- if (m_Video != null)
- {
- m_Video.Call("Play");
- }
- }
- public override void Pause()
- {
- if (m_Video != null)
- {
- m_Video.Call("Pause");
- }
- }
- public override void Stop()
- {
- if (m_Video != null)
- {
-
- m_Video.Call("Pause");
- }
- }
- public override void Seek(double time)
- {
- if (m_Video != null)
- {
-
- m_Video.Call("Seek", time);
- }
- }
- public override void SeekFast(double time)
- {
- if (m_Video != null)
- {
-
- m_Video.Call("SeekFast", time);
- }
- }
- public override double GetCurrentTime()
- {
- double result = 0.0;
- if (m_Video != null)
- {
- if (m_Method_GetCurrentTimeS != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallDoubleMethod(m_Video.GetRawObject(), m_Method_GetCurrentTimeS, m_Value0);
- }
- else
- {
- result = (double)m_Video.Call<double>("GetCurrentTimeS");
- }
- }
- return result;
- }
- public override void SetPlaybackRate(float rate)
- {
- if (m_Video != null)
- {
- m_Video.Call("SetPlaybackRate", rate);
- }
- }
- public override float GetPlaybackRate()
- {
- float result = 0.0f;
- if (m_Video != null)
- {
- result = m_Video.Call<float>("GetPlaybackRate");
- }
- return result;
- }
- public override void SetAudioHeadRotation(Quaternion q)
- {
- if (m_Video != null)
- {
- if (!m_HeadRotationEnabled)
- {
- m_Video.Call("SetPositionTrackingEnabled", true);
- m_HeadRotationEnabled = true;
- }
- if (m_Method_SetHeadRotation != System.IntPtr.Zero)
- {
- m_Value4[0].f = q.x;
- m_Value4[1].f = q.y;
- m_Value4[2].f = q.z;
- m_Value4[3].f = q.w;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetHeadRotation, m_Value4);
- }
- else
- {
- m_Video.Call("SetHeadRotation", q.x, q.y, q.z, q.w);
- }
- }
- }
- public override void ResetAudioHeadRotation()
- {
- if (m_Video != null && m_HeadRotationEnabled)
- {
- m_Video.Call("SetPositionTrackingEnabled", false);
- m_HeadRotationEnabled = false;
- }
- }
- public override void SetAudioFocusEnabled(bool enabled)
- {
- if (m_Video != null && enabled != m_FocusEnabled)
- {
- if (m_Method_SetFocusEnabled != System.IntPtr.Zero)
- {
- m_Value1[0].z = enabled;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusEnabled, m_Value1);
- }
- else
- {
- m_Video.Call("SetFocusEnabled", enabled);
- }
- m_FocusEnabled = enabled;
- }
- }
- public override void SetAudioFocusProperties(float offFocusLevel, float widthDegrees)
- {
- if(m_Video != null && m_FocusEnabled)
- {
- if (m_Method_SetFocusProps != System.IntPtr.Zero)
- {
- m_Value2[0].f = offFocusLevel;
- m_Value2[1].f = widthDegrees;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusProps, m_Value2);
- }
- else
- {
- m_Video.Call("SetFocusProps", offFocusLevel, widthDegrees);
- }
- }
- }
- public override void SetAudioFocusRotation(Quaternion q)
- {
- if (m_Video != null && m_FocusEnabled)
- {
- if (m_Method_SetFocusRotation != System.IntPtr.Zero)
- {
- m_Value4[0].f = q.x;
- m_Value4[1].f = q.y;
- m_Value4[2].f = q.z;
- m_Value4[3].f = q.w;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusRotation, m_Value4);
- }
- else
- {
- m_Video.Call("SetFocusRotation", q.x, q.y, q.z, q.w);
- }
- }
- }
- public override void ResetAudioFocus()
- {
- if (m_Video != null)
- {
- if (m_Method_SetFocusProps != System.IntPtr.Zero &&
- m_Method_SetFocusEnabled != System.IntPtr.Zero &&
- m_Method_SetFocusRotation != System.IntPtr.Zero)
- {
- m_Value2[0].f = 0f;
- m_Value2[1].f = 90f;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusProps, m_Value2);
- m_Value1[0].z = false;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusEnabled, m_Value1);
- m_Value4[0].f = 0f;
- m_Value4[1].f = 0f;
- m_Value4[2].f = 0f;
- m_Value4[3].f = 1f;
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_SetFocusRotation, m_Value4);
- }
- else
- {
- m_Video.Call("SetFocusProps", 0f, 90f);
- m_Video.Call("SetFocusEnabled", false);
- m_Video.Call("SetFocusRotation", 0f, 0f, 0f, 1f);
- }
- }
- }
- public override double GetDuration()
- {
- return m_Duration;
- }
- public override int GetVideoWidth()
- {
- return m_Width;
- }
-
- public override int GetVideoHeight()
- {
- return m_Height;
- }
- public override float GetVideoFrameRate()
- {
- float result = 0.0f;
- if( m_Video != null )
- {
- if (m_Method_GetSourceVideoFrameRate != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallFloatMethod(m_Video.GetRawObject(), m_Method_GetSourceVideoFrameRate, m_Value0);
- }
- else
- {
- result = m_Video.Call<float>("GetSourceVideoFrameRate");
- }
- }
- return result;
- }
- public override float GetVideoDisplayRate()
- {
- float result = 0.0f;
- #if DLL_METHODS
- result = Native._GetVideoDisplayRate( m_iPlayerIndex );
- #else
- if (m_Video != null)
- {
- result = m_Video.Call<float>("GetDisplayRate");
- }
- #endif
- return result;
- }
- public override bool IsSeeking()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_IsSeeking != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsSeeking, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsSeeking");
- }
- }
- return result;
- }
- public override bool IsPlaying()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_IsPlaying != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsPlaying, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsPlaying");
- }
- }
- return result;
- }
- public override bool IsPaused()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_IsPaused != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsPaused, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsPaused");
- }
- }
- return result;
- }
- public override bool IsFinished()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_IsFinished != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsFinished, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsFinished");
- }
- }
- return result;
- }
- public override bool IsBuffering()
- {
- bool result = false;
- if (m_Video != null)
- {
- if (m_Method_IsBuffering != System.IntPtr.Zero)
- {
- result = AndroidJNI.CallBooleanMethod(m_Video.GetRawObject(), m_Method_IsBuffering, m_Value0);
- }
- else
- {
- result = m_Video.Call<bool>("IsBuffering");
- }
- }
- return result;
- }
- public override Texture GetTexture( int index )
- {
- Texture result = null;
- if (GetTextureFrameCount() > 0)
- {
- result = m_Texture;
- }
- return result;
- }
- public override int GetTextureFrameCount()
- {
- int result = 0;
- if( m_Texture != null )
- {
- #if DLL_METHODS
- result = Native._GetFrameCount( m_iPlayerIndex );
- #else
- if (m_Video != null)
- {
- result = m_Video.Call<int>("GetFrameCount");
- }
- #endif
- }
- return result;
- }
- internal override StereoPacking InternalGetTextureStereoPacking()
- {
- StereoPacking result = StereoPacking.Unknown;
- if (m_Video != null)
- {
- NativeStereoPacking internalStereoMode = (NativeStereoPacking)( m_Video.Call<int>("GetCurrentVideoTrackStereoMode") );
- switch( internalStereoMode )
- {
- case NativeStereoPacking.Monoscopic: result = StereoPacking.None; break;
- case NativeStereoPacking.TopBottom: result = StereoPacking.TopBottom; break;
- case NativeStereoPacking.LeftRight: result = StereoPacking.LeftRight; break;
- case NativeStereoPacking.Mesh: result = StereoPacking.Unknown; break;
- }
- }
- return result;
- }
- public override bool RequiresVerticalFlip()
- {
- return false;
- }
- public override void MuteAudio(bool bMuted)
- {
- if (m_Video != null)
- {
- m_Video.Call("MuteAudio", bMuted);
- }
- }
- public override bool IsMuted()
- {
- bool result = false;
- if( m_Video != null )
- {
- result = m_Video.Call<bool>("IsMuted");
- }
- return result;
- }
- public override void SetVolume(float volume)
- {
- if (m_Video != null)
- {
- m_Video.Call("SetVolume", volume);
- }
- }
- public override float GetVolume()
- {
- float result = 0.0f;
- if( m_Video != null )
- {
- result = m_Video.Call<float>("GetVolume");
- }
- return result;
- }
- public override void SetBalance(float balance)
- {
- if( m_Video != null )
- {
- m_Video.Call("SetAudioPan", balance);
- }
- }
- public override float GetBalance()
- {
- float result = 0.0f;
- if( m_Video != null )
- {
- result = m_Video.Call<float>("GetAudioPan");
- }
- return result;
- }
- public override bool WaitForNextFrame(Camera dummyCamera, int previousFrameCount)
- {
-
- bool isMultiThreaded = m_Video.Call<bool>("StartExtractFrame");
-
- if (isMultiThreaded)
- {
-
- IssuePluginEvent(Native.AVPPluginEvent.ExtractFrame, m_iPlayerIndex);
-
- dummyCamera.Render();
-
- m_Video.Call("WaitForExtract");
-
- return (previousFrameCount != GetTextureFrameCount());
- }
- return false;
- }
- public override long GetTextureTimeStamp()
- {
- long timeStamp = long.MinValue;
- if (m_Video != null)
- {
- timeStamp = m_Video.Call<long>("GetTextureTimeStamp");
- }
- return timeStamp;
- }
- public override void Render()
- {
- if (m_Video != null)
- {
- if (m_UseFastOesPath)
- {
-
- GL.InvalidateState();
- }
- AndroidMediaPlayer.IssuePluginEvent( Native.AVPPluginEvent.PlayerUpdate, m_iPlayerIndex );
- if (m_UseFastOesPath)
- {
- GL.InvalidateState();
- }
- }
- }
- public override void OnEnable()
- {
- base.OnEnable();
- #if DLL_METHODS
- int textureHandle = Native._GetTextureHandle(m_iPlayerIndex);
- #else
- int textureHandle = m_Video.Call<int>("GetTextureHandle");
- #endif
- if (m_Texture != null && textureHandle > 0 && m_Texture.GetNativeTexturePtr() == System.IntPtr.Zero)
- {
-
- m_Texture.UpdateExternalTexture(new System.IntPtr(textureHandle));
- }
- #if AVPROVIDEO_FIXREGRESSION_TEXTUREQUALITY_UNITY542
- #if UNITY_2022_2_OR_NEWER
-
- _textureQuality = QualitySettings.globalTextureMipmapLimit;
- #else
- _textureQuality = QualitySettings.masterTextureLimit;
- #endif
- #endif
- }
- public override System.DateTime GetProgramDateTime()
- {
- System.DateTime result;
- if (m_Video != null)
- {
- double seconds = m_Video.Call<double>("GetCurrentAbsoluteTimestamp");
- result = Helper.ConvertSecondsSince1970ToDateTime(seconds);
- }
- else
- {
- result = base.GetProgramDateTime();
- }
- return result;
- }
- public override void Update()
- {
- if (m_Video != null)
- {
- if (m_Method_Update != System.IntPtr.Zero)
- {
- AndroidJNI.CallVoidMethod(m_Video.GetRawObject(), m_Method_Update, m_Value0);
- }
- else
- {
- m_Video.Call("Update");
- }
- _lastError = (ErrorCode)( Native._GetLastErrorCode( m_iPlayerIndex ) );
- }
- if( m_Options.HasChanged( MediaPlayer.OptionsAndroid.ChangeFlags.All, true ) )
- {
- if (m_Video != null)
- {
- #if UNITY_2017_2_OR_NEWER
- Vector2 vPreferredVideo = GetPreferredVideoResolution(m_Options.preferredMaximumResolution, m_Options.customPreferredMaximumResolution);
- #else
- Vector2 vPreferredVideo = GetPreferredVideoResolution(m_Options.preferredMaximumResolution, new Vector2(0.0f, 0.0f));
- #endif
- int iNewBitrate = (int)(m_Options.GetPreferredPeakBitRateInBitsPerSecond());
- m_Video.Call<bool>("SetPreferredVideoResolutionAndBitrate", (int)(vPreferredVideo.x), (int)(vPreferredVideo.y), iNewBitrate);
- }
- }
-
- UpdateTracks();
- UpdateTextCue();
- UpdateSubtitles();
- UpdateTimeRanges();
- UpdateDisplayFrameRate();
- if (Mathf.Approximately((float)m_Duration, 0f))
- {
- #if DLL_METHODS
- m_Duration = (double)( Native._GetDuration( m_iPlayerIndex ) );
- #else
- m_Duration = m_Video.Call<double>("GetDurationS");
- #endif
- }
-
-
- int newWidth = -1;
- int newHeight = -1;
- if (m_Texture != null)
- {
- #if DLL_METHODS
- newWidth = Native._GetWidth(m_iPlayerIndex);
- newHeight = Native._GetHeight(m_iPlayerIndex);
- #else
- newWidth = m_Video.Call<int>("GetWidth");
- newHeight = m_Video.Call<int>("GetHeight");
- #endif
- if (newWidth != m_Width || newHeight != m_Height)
- {
- m_Texture = null;
- m_TextureHandle = 0;
- }
- }
- #if DLL_METHODS
- int textureHandle = Native._GetTextureHandle(m_iPlayerIndex);
- #else
- int textureHandle = m_Video.Call<int>("GetTextureHandle");
- #endif
- if (textureHandle != 0 && textureHandle != m_TextureHandle)
- {
-
- if (newWidth == -1 || newHeight == -1)
- {
- #if DLL_METHODS
- newWidth = Native._GetWidth(m_iPlayerIndex);
- newHeight = Native._GetHeight(m_iPlayerIndex);
- #else
- newWidth = m_Video.Call<int>("GetWidth");
- newHeight = m_Video.Call<int>("GetHeight");
- #endif
- }
- if (Mathf.Max(newWidth, newHeight) > SystemInfo.maxTextureSize)
- {
- m_Width = newWidth;
- m_Height = newHeight;
- m_TextureHandle = textureHandle;
- Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize");
- }
- else if (newWidth > 0 && newHeight > 0)
- {
- m_Width = newWidth;
- m_Height = newHeight;
- m_TextureHandle = textureHandle;
- switch (m_API)
- {
- case Android.VideoApi.MediaPlayer:
- _playerDescription = "MediaPlayer";
- break;
- case Android.VideoApi.ExoPlayer:
- _playerDescription = "ExoPlayer";
- break;
- default:
- _playerDescription = "UnknownPlayer";
- break;
- }
- if (m_UseFastOesPath)
- {
- _playerDescription += " OES";
- }
- else
- {
- _playerDescription += " NonOES";
- }
- Helper.LogInfo("Using playback path: " + _playerDescription + " (" + m_Width + "x" + m_Height + "@" + GetVideoFrameRate().ToString("F2") + ")");
-
-
- m_Texture = Texture2D.CreateExternalTexture(m_Width, m_Height, TextureFormat.RGBA32, false, false, new System.IntPtr(textureHandle));
- if (m_Texture != null)
- {
- ApplyTextureProperties(m_Texture);
- }
- Helper.LogInfo("Texture ID: " + textureHandle);
- }
- }
- #if AVPROVIDEO_FIXREGRESSION_TEXTUREQUALITY_UNITY542
- #if UNITY_2022_2_OR_NEWER
-
- int textureQualityToTestAgainst = QualitySettings.globalTextureMipmapLimit;
- #else
- int textureQualityToTestAgainst = QualitySettings.masterTextureLimit;
- #endif
-
-
-
-
- if (_textureQuality != textureQualityToTestAgainst)
- {
- if (m_Texture != null && textureHandle > 0 && m_Texture.GetNativeTexturePtr() == System.IntPtr.Zero)
- {
-
- m_Texture.UpdateExternalTexture(new System.IntPtr(textureHandle));
- }
- _textureQuality = textureQualityToTestAgainst;
- }
- #endif
- }
- protected override void ApplyTextureProperties(Texture texture)
- {
-
-
-
-
-
-
- {
- base.ApplyTextureProperties(texture);
- }
- }
- public override bool PlayerSupportsLinearColorSpace()
- {
- return false;
- }
- public override float[] GetTextureTransform()
- {
- float[] transform = null;
- if (m_Video != null)
- {
- transform = m_Video.Call<float[]>("GetTextureTransform");
-
- }
- return transform;
- }
- public override void Dispose()
- {
-
- if (m_Video != null)
- {
- m_Video.Call("SetDeinitialiseFlagged");
- m_Video.Dispose();
- m_Video = null;
- }
- if (s_Interface != null)
- {
- s_Interface.Call("DestroyPlayer", m_iPlayerIndex);
- }
- if (m_Texture != null)
- {
- Texture2D.Destroy(m_Texture);
- m_Texture = null;
- }
-
- AndroidMediaPlayer.IssuePluginEvent( Native.AVPPluginEvent.PlayerDestroy, m_iPlayerIndex );
- }
- private void UpdateTimeRanges()
- {
- if( m_Video != null )
- {
-
- AndroidJavaObject seekableReturnObject = m_Video.Call<AndroidJavaObject>("GetSeekableTimeRanges");
- if( seekableReturnObject.GetRawObject().ToInt32() != 0 )
- {
- double[] aSeekableRanges = AndroidJNIHelper.ConvertFromJNIArray<double[]>( seekableReturnObject.GetRawObject() );
- if( aSeekableRanges.Length > 1 )
- {
- int iNumRanges = aSeekableRanges.Length / 2;
- _seekableTimes._ranges = new TimeRange[ iNumRanges ];
- int iRangeIndex = 0;
- for( int iRange = 0; iRange < iNumRanges; ++iRange )
- {
- _seekableTimes._ranges[ iRange ] = new TimeRange( aSeekableRanges[ iRangeIndex ], aSeekableRanges[ iRangeIndex + 1 ] );
- iRangeIndex += 2;
- }
- _seekableTimes.CalculateRange();
- }
- seekableReturnObject.Dispose();
- }
-
- AndroidJavaObject bufferedReturnObject = m_Video.Call<AndroidJavaObject>("GetBufferedTimeRanges");
- if( bufferedReturnObject.GetRawObject().ToInt32() != 0 )
- {
- double[] aBufferedRanges = AndroidJNIHelper.ConvertFromJNIArray<double[]>( bufferedReturnObject.GetRawObject() );
- if( aBufferedRanges.Length > 1 )
- {
- int iNumRanges = aBufferedRanges.Length / 2;
- _bufferedTimes._ranges = new TimeRange[ iNumRanges ];
- int iRangeIndex = 0;
- for( int iRange = 0; iRange < iNumRanges; ++iRange )
- {
- _bufferedTimes._ranges[iRange] = new TimeRange( aBufferedRanges[iRangeIndex], aBufferedRanges[iRangeIndex + 1] );
- iRangeIndex += 2;
- }
- _bufferedTimes.CalculateRange();
- }
- bufferedReturnObject.Dispose();
- }
- }
- }
- bool isMainThread()
- {
- return m_MainThread.Equals(System.Threading.Thread.CurrentThread);
- }
- public override int GetAudioChannelCount()
- {
- return Native._GetCurrentAudioTrackNumChannels(m_iPlayerIndex);
- }
- public override int GrabAudio(float[] buffer, int sampleCount, int channelCount)
- {
- int iReturn = 0;
-
- iReturn = Native._GrabAudioNative( buffer, m_iPlayerIndex, sampleCount, channelCount );
- return iReturn;
- }
- public override int GetAudioBufferedSampleCount()
- {
- int iBufferedSampleCount = 0;
- if (m_Video != null)
- {
-
- iBufferedSampleCount = m_Video.Call<int>("GetAudioBufferedSampleCount");
- }
- return iBufferedSampleCount;
- }
- internal override bool InternalIsChangedTextCue()
- {
-
- if( m_Video != null )
- {
- return m_Video.Call<bool>("GetTextCueDirty");
- }
- return false;
- }
- internal override string InternalGetCurrentTextCue()
- {
-
- if ( m_Video != null )
- {
- return m_Video.Call<string>("GetCurrentTextCue");
- }
- return string.Empty;
- }
- internal override bool InternalIsChangedTracks(TrackType trackType)
- {
-
- bool result = false;
- switch (trackType)
- {
- case TrackType.Video:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("GetVideoTracksDirty") : false;
- break;
- }
- case TrackType.Audio:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("GetAudioTracksDirty") : false;
- break;
- }
- case TrackType.Text:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("GetTextTracksDirty") : false;
- break;
- }
- }
- return result;
- }
- internal override int InternalGetTrackCount(TrackType trackType)
- {
- int result = 0;
- switch (trackType)
- {
- case TrackType.Video:
- {
- result = ( m_Video != null ) ? m_Video.Call<int>("GetNumberVideoTracks") : 0;
- break;
- }
- case TrackType.Audio:
- {
- result = ( m_Video != null ) ? m_Video.Call<int>("GetNumberAudioTracks") : 0;
- break;
- }
- case TrackType.Text:
- {
- result = ( m_Video != null ) ? m_Video.Call<int>("GetNumberTextTracks") : 0;
- break;
- }
- }
- return result;
- }
- internal override bool InternalSetActiveTrack(TrackType trackType, int trackUid)
- {
- bool result = false;
- switch (trackType)
- {
- case TrackType.Video:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("SetVideoTrack", trackUid) : false;
- break;
- }
- case TrackType.Audio:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("SetAudioTrack", trackUid) : false;
- break;
- }
- case TrackType.Text:
- {
- result = ( m_Video != null ) ? m_Video.Call<bool>("SetTextTrack", trackUid) : false;
- break;
- }
- }
- return result;
- }
- internal override TrackBase InternalGetTrackInfo(TrackType trackType, int trackIndex, ref bool isActiveTrack)
- {
- TrackBase result = null;
- switch (trackType)
- {
- case TrackType.Video:
- {
- if (m_Video != null)
- {
- AndroidJavaObject returnObject = m_Video.Call<AndroidJavaObject>("GetVideoTrackInfo", trackIndex);
- if (returnObject.GetRawObject().ToInt32() != 0)
- {
- String[] aReturn = AndroidJNIHelper.ConvertFromJNIArray<String[]>(returnObject.GetRawObject());
- bool bReturn = (aReturn.Length > 0) ? (int.Parse(aReturn[0]) == 1) : false;
- if (bReturn)
- {
- VideoTrack videoTrack = new VideoTrack(trackIndex, aReturn[1], aReturn[2], (aReturn[3] == "1"));
- int bitrate = 0;
- bool gotBitrate = Int32.TryParse(aReturn[4], out bitrate);
- if( gotBitrate )
- {
- videoTrack.Bitrate = bitrate;
- }
- result = videoTrack;
- isActiveTrack = (m_Video != null && m_Video.Call<int>("GetCurrentVideoTrackIndex") == trackIndex);
- }
- returnObject.Dispose();
- }
- }
- }
- break;
- case TrackType.Audio:
- {
- if (m_Video != null)
- {
- AndroidJavaObject returnObject = m_Video.Call<AndroidJavaObject>("GetAudioTrackInfo", trackIndex);
- if (returnObject.GetRawObject().ToInt32() != 0)
- {
- String[] aReturn = AndroidJNIHelper.ConvertFromJNIArray<String[]>( returnObject.GetRawObject() );
- bool bReturn = ( aReturn.Length > 0 ) ? ( int.Parse( aReturn[ 0 ]) == 1 ) : false;
- if (bReturn)
- {
- int iBitrate = 0;
- int.TryParse( aReturn[ 4 ], out iBitrate );
- int iChannelCount = 0;
- int.TryParse(aReturn[ 5 ], out iChannelCount);
- result = new AudioTrack( trackIndex, aReturn[ 1 ], aReturn[ 2 ], (aReturn[ 3 ] == "1") );
- isActiveTrack = (m_Video != null && m_Video.Call<int>("GetCurrentAudioTrackIndex") == trackIndex);
- }
- returnObject.Dispose();
- }
- }
- }
- break;
-
- case TrackType.Text:
- {
- if (m_Video != null)
- {
- AndroidJavaObject returnObject = m_Video.Call<AndroidJavaObject>( "GetTextTrackInfo", trackIndex );
- if (returnObject.GetRawObject().ToInt32() != 0)
- {
- String[] aReturn = AndroidJNIHelper.ConvertFromJNIArray<String[]>( returnObject.GetRawObject() );
- bool bReturn = ( aReturn.Length > 0 ) ? ( int.Parse(aReturn[ 0 ] ) == 1 ) : false;
- int uid = -1;
- if( bReturn )
- {
- int.TryParse(aReturn[1], out uid);
- result = new TextTrack(uid, aReturn[ 2 ], aReturn[ 3 ], false);
- isActiveTrack = (m_Video != null && m_Video.Call<int>("GetCurrentTextTrackIndex") == trackIndex);
- }
- returnObject.Dispose();
- }
- }
- }
- break;
- }
- return result;
- }
- internal int InternalGetAdaptiveStreamCount(TrackType trackType, int trackIndex = -1)
- {
- int result = 0;
- switch (trackType)
- {
- case TrackType.Video:
- {
- result = (m_Video != null) ? m_Video.Call<int>("GetNumberVideoAdaptiveStreams", trackIndex) : 0;
- Debug.Log("[AVProVideo]: InternalGetAdaptiveStreamCount return = " + result);
- break;
- }
- case TrackType.Audio:
- {
- break;
- }
- case TrackType.Text:
- {
- break;
- }
- }
- return result;
- }
- internal void InternalGetAdaptiveStreamInfo(TrackType trackType, int trackIndex = -1)
- {
- switch( trackType )
- {
- case TrackType.Video:
- {
- if( m_Video != null )
- {
- AndroidJavaObject returnObject = m_Video.Call<AndroidJavaObject>("GetVideoAdaptiveStreamInfo", trackIndex);
- if( returnObject.GetRawObject().ToInt32() != 0 )
- {
- String[] aReturn = AndroidJNIHelper.ConvertFromJNIArray<String[]>(returnObject.GetRawObject());
- bool bReturn = (aReturn.Length > 0) ? (int.Parse(aReturn[0]) == 1) : false;
- string toLog = "";
- foreach( string str in aReturn ) { toLog += str + ", "; }
- Debug.Log( "[AVProVideo]: InternalGetAdaptiveStreamInfo return = " + toLog );
- if ( bReturn )
- {
- }
- returnObject.Dispose();
- }
- }
- }
- break;
- case TrackType.Audio:
- {
- }
- break;
- case TrackType.Text:
- {
- }
- break;
- }
- }
- internal int SetVideoAdaptiveStreamIndex(TrackType trackType, int streamIndex)
- {
- int result = 0;
- switch( trackType )
- {
- case TrackType.Video:
- {
- Debug.Log("[AVProVideo]: SetVideoAdaptiveStreamIndex : streamIndex = " + streamIndex);
- result = (m_Video != null) ? m_Video.Call<int>("SetVideoAdaptiveStreams", streamIndex) : 0;
- break;
- }
- case TrackType.Audio:
- {
- break;
- }
- case TrackType.Text:
- {
- break;
- }
- }
- return result;
- }
- private Vector2 GetPreferredVideoResolution(MediaPlayer.OptionsAndroid.Resolution preferredMaximumResolution, Vector2 customPreferredMaximumResolution)
- {
- Vector2 vResolution = new Vector2( 0.0f, 0.0f );
- switch( preferredMaximumResolution )
- {
- case MediaPlayer.OptionsAndroid.Resolution.NoPreference:
- break;
- case MediaPlayer.OptionsAndroid.Resolution._480p:
- vResolution.x = 640;
- vResolution.y = 480;
- break;
- case MediaPlayer.OptionsAndroid.Resolution._720p:
- vResolution.x = 1280;
- vResolution.y = 720;
- break;
- case MediaPlayer.OptionsAndroid.Resolution._1080p:
- vResolution.x = 1920;
- vResolution.y = 1080;
- break;
- case MediaPlayer.OptionsAndroid.Resolution._2160p:
- vResolution.x = 3840;
- vResolution.y = 2160;
- break;
- case MediaPlayer.OptionsAndroid.Resolution.Custom:
- #if UNITY_2017_2_OR_NEWER
- vResolution.x = customPreferredMaximumResolution.x;
- vResolution.y = customPreferredMaximumResolution.y;
- #endif
- break;
- }
- return vResolution;
- }
- public override bool IsMediaCachingSupported()
- {
- if( m_Video != null )
- {
- return m_Video.Call<bool>("IsMediaCachingSupported");
- }
- return true;
- }
- public override void AddMediaToCache(string url, string headers, MediaCachingOptions options)
- {
- if (m_Video != null)
- {
- double dMinBitrate = -1.0f;
- int iMinWidth = -1;
- int iMinHeight = -1;
- double dMaxBitrate = -1.0f;
- int iMaxWidth = -1;
- int iMaxHeight = -1;
-
- if (options != null )
- {
- dMinBitrate = options.minimumRequiredBitRate;
- iMinWidth = (int)( options.minimumRequiredResolution.x );
- iMinHeight = (int)( options.minimumRequiredResolution.y );
- dMaxBitrate = options.maximumRequiredBitRate;
- iMaxWidth = (int)(options.maximumRequiredResolution.x);
- iMaxHeight = (int)(options.maximumRequiredResolution.y);
- }
- m_Video.Call("AddMediaToCache", url, headers, dMinBitrate, iMinWidth, iMinHeight, dMaxBitrate, iMaxWidth, iMaxHeight);
- }
- }
- public override void RemoveMediaFromCache(string url)
- {
- if(m_Video != null)
- {
- m_Video.Call("RemoveMediaFromCache", url);
- }
- }
- public override void CancelDownloadOfMediaToCache(string url)
- {
- if (m_Video != null)
- {
- m_Video.Call("CancelDownloadOfMediaToCache", url);
- }
- }
- public override void PauseDownloadOfMediaToCache(string url)
- {
- if (m_Video != null)
- {
- m_Video.Call("PauseDownloadOfMediaToCache", url);
- }
- }
- public override void ResumeDownloadOfMediaToCache(string url)
- {
- if (m_Video != null)
- {
- m_Video.Call("ResumeDownloadOfMediaToCache", url);
- }
- }
- public override CachedMediaStatus GetCachedMediaStatus(string url, ref float progress)
- {
- CachedMediaStatus eStatus = CachedMediaStatus.NotCached;
- if (m_Video != null)
- {
- float[] afReturn = m_Video.Call<float[]>("GetCachedMediaStatus", url);
- eStatus = (CachedMediaStatus)( afReturn[ 0 ] );
- progress = afReturn[ 1 ] * 0.01f;
- }
- return eStatus;
- }
- private struct Native
- {
- internal const string LibraryName = "AVProVideo2Native";
- [DllImport (LibraryName)]
- public static extern IntPtr GetRenderEventFunc();
- [DllImport(LibraryName)]
- public static extern bool JNIAttachCurrentThread();
- [DllImport(LibraryName)]
- public static extern void JNIDetachCurrentThread();
- [DllImport(LibraryName)]
- public static extern int _GetCurrentAudioTrackNumChannels( int iPlayerIndex );
- [DllImport(LibraryName)]
- public static extern int _GrabAudioNative(float[] pBuffer, int iPlayerIndex, int sampleCount, int channelCount);
- [DllImport (LibraryName)]
- public static extern int _GetWidth( int iPlayerIndex );
- [DllImport (LibraryName)]
- public static extern int _GetHeight( int iPlayerIndex );
-
- [DllImport (LibraryName)]
- public static extern int _GetTextureHandle( int iPlayerIndex );
- [DllImport (LibraryName)]
- public static extern double _GetDuration( int iPlayerIndex );
- [DllImport (LibraryName)]
- public static extern int _GetLastErrorCode( int iPlayerIndex );
- [DllImport (LibraryName)]
- public static extern int _GetFrameCount( int iPlayerIndex );
-
- [DllImport (LibraryName)]
- public static extern float _GetVideoDisplayRate( int iPlayerIndex );
- [DllImport (LibraryName)]
- public static extern bool _CanPlay( int iPlayerIndex );
-
- public enum AVPPluginEvent
- {
- Nop,
- PlayerSetup,
- PlayerUpdate,
- PlayerDestroy,
- ExtractFrame,
- }
- }
- }
- }
- #endif
-
|