Files
ZHGD_Web/Assets/UniversalMediaPlayer/Scripts/Sources/Wrappers/WrapperInternal.cs

378 lines
12 KiB
C#
Raw Normal View History

2025-07-13 23:16:20 +08:00
using System;
using System.Runtime.InteropServices;
namespace UMP.Wrappers
{
2025-07-15 18:33:21 +08:00
internal class WrapperInternal : IWrapperNative, IWrapperPlayer
{
#region iOS/WebGL Imports
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
private int _nativeIndex;
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern IntPtr UMPNativeInit();
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPNativeInitPlayer(int index, string options);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPNativeUpdateTexture(int index, IntPtr texture);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern IntPtr UMPNativeGetTexturePointer(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPNativeSetPixelsBuffer(int index, IntPtr buffer, int width, int height);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPNativeUpdateFrameBuffer(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetDataSource(int index, string path);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern bool UMPPlay(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPPause(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPStop(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPRelease(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern bool UMPIsPlaying(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern bool UMPIsReady(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPGetLength(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPGetTime(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetTime(int index, int time);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern float UMPGetPosition(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetPosition(int index, float position);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern float UMPGetRate(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetRate(int index, float rate);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPGetVolume(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetVolume(int index, int volume);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern bool UMPGetMute(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern void UMPSetMute(int index, bool state);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPVideoWidth(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPVideoHeight(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPVideoFrameCount(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern int UMPGetState(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern float UMPGetStateFloatValue(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern long UMPGetStateLongValue(int index);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
[DllImport("__Internal")]
private static extern IntPtr UMPGetStateStringValue(int index);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
#endregion
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public WrapperInternal(PlayerOptionsIPhone options)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
_nativeIndex = (int)UMPNativeInit();
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
#region Native
public int NativeIndex
{
get
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
return _nativeIndex;
2025-07-13 23:16:20 +08:00
#else
return 0;
#endif
2025-07-15 18:33:21 +08:00
}
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void NativeInitPlayer(string options)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
UMPNativeInitPlayer(_nativeIndex, options);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public IntPtr NativeGetTexture()
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
return UMPNativeGetTexturePointer(_nativeIndex);
2025-07-13 23:16:20 +08:00
#else
return IntPtr.Zero;
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void NativeUpdateTexture(IntPtr texture)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
UMPNativeUpdateTexture(_nativeIndex, texture);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void NativeSetPixelsBuffer(IntPtr buffer, int width, int height)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
UMPNativeSetPixelsBuffer(_nativeIndex, buffer, width, height);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void NativeUpdatePixelsBuffer()
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
UMPNativeUpdateFrameBuffer(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
#endregion
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
#region Player
public void PlayerSetDataSource(string path, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetDataSource(_nativeIndex, path);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public bool PlayerPlay(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
return UMPPlay(_nativeIndex);
2025-07-13 23:16:20 +08:00
#else
return false;
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerPause(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPPause(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerStop(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPStop(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerRelease(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPRelease(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public bool PlayerIsPlaying(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPIsPlaying(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return false;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public bool PlayerIsReady(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPIsReady(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return false;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public long PlayerGetLength(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetLength(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public long PlayerGetTime(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetTime(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerSetTime(long time, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetTime(_nativeIndex, (int)time);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public float PlayerGetPosition(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetPosition(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerSetPosition(float pos, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetPosition(_nativeIndex, pos);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public float PlayerGetRate(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetRate(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 1;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public bool PlayerSetRate(float rate, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetRate(_nativeIndex, rate);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return true;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public int PlayerGetVolume(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetVolume(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public int PlayerSetVolume(int volume, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetVolume(_nativeIndex, volume);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 1;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public bool PlayerGetMute(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPGetMute(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return false;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public void PlayerSetMute(bool mute, object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
UMPSetMute(_nativeIndex, mute);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public int PlayerVideoWidth(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPVideoWidth(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public int PlayerVideoHeight(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPVideoHeight(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public int PlayerVideoFramesCounter(object playerObject = null)
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
return UMPVideoFrameCount(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return 0;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public PlayerState PlayerGetState()
{
var eventValue = PlayerState.Empty;
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
if (_nativeIndex >= 0)
eventValue = (PlayerState)UMPGetState(_nativeIndex);
2025-07-13 23:16:20 +08:00
#endif
2025-07-15 18:33:21 +08:00
return eventValue;
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
public object PlayerGetStateValue()
{
2025-07-13 23:16:20 +08:00
#if UNITY_IOS || UNITY_WEBGL
2025-07-15 18:33:21 +08:00
object value = UMPGetStateFloatValue(_nativeIndex);
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
if ((float)value < 0)
{
value = UMPGetStateLongValue(_nativeIndex);
if ((long)value < 0)
value = UMPGetStateStringValue(_nativeIndex);
}
2025-07-13 23:16:20 +08:00
2025-07-15 18:33:21 +08:00
return value;
2025-07-13 23:16:20 +08:00
#else
return null;
#endif
2025-07-15 18:33:21 +08:00
}
#endregion
2025-07-13 23:16:20 +08:00
}
}