123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- using System;
- namespace Agora.Rtc
- {
- public sealed class MediaPlayer : IMediaPlayer
- {
- private IRtcEngine _rtcEngineInstance = null;
- private MediaPlayerImpl _mediaPlayerImpl = null;
- private const int ErrorCode = -7;
- private int playerId;
- internal MediaPlayer(IRtcEngine rtcEngine, MediaPlayerImpl impl)
- {
- _rtcEngineInstance = rtcEngine;
- _mediaPlayerImpl = impl;
- playerId = _mediaPlayerImpl.CreateMediaPlayer();
- }
- ~MediaPlayer()
- {
- _mediaPlayerImpl = null;
- _rtcEngineInstance = null;
- }
- public override void Dispose()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.DestroyMediaPlayer(playerId);
- playerId = 0;
- }
- public override int GetId()
- {
- return playerId;
- }
- public override void InitEventHandler(IMediaPlayerSourceObserver engineEventHandler)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.InitEventHandler(playerId, engineEventHandler);
- }
- public override void RegisterAudioFrameObserver(IMediaPlayerAudioFrameObserver observer)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.RegisterAudioFrameObserver(playerId, observer);
- }
- public override void RegisterAudioFrameObserver(IMediaPlayerAudioFrameObserver observer, RAW_AUDIO_FRAME_OP_MODE_TYPE mode)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.RegisterAudioFrameObserver(playerId, observer, mode);
- }
- public override void UnregisterAudioFrameObserver()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.UnregisterAudioFrameObserver(playerId);
- }
- public override void RegisterMediaPlayerAudioSpectrumObserver(IAudioSpectrumObserver observer, int intervalInMS)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.RegisterMediaPlayerAudioSpectrumObserver(playerId, observer, intervalInMS);
- }
- public override void UnregisterMediaPlayerAudioSpectrumObserver()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return;
- }
- _mediaPlayerImpl.UnregisterMediaPlayerAudioSpectrumObserver(playerId);
- }
- public override int Open(string url, Int64 startPos)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Open(playerId, url, startPos);
- }
- public override int OpenWithCustomSource(Int64 startPos, IMediaPlayerCustomDataProvider provider)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.OpenWithCustomSource(playerId, startPos, provider);
- }
- public override int OpenWithMediaSource(MediaSource source)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.OpenWithMediaSource(playerId, source);
- }
- public override int SetSoundPositionParams(float pan, float gain)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetSoundPositionParams(pan, gain);
- }
- public override int Play()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Play(playerId);
- }
- public override int Pause()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Pause(playerId);
- }
- public override int Stop()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Stop(playerId);
- }
- public override int Resume()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Resume(playerId);
- }
- public override int Seek(Int64 newPos)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Seek(playerId, newPos);
- }
- public override int GetDuration(ref Int64 duration)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetDuration(playerId, ref duration);
- }
- public override int GetPlayPosition(ref Int64 pos)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetPlayPosition(playerId, ref pos);
- }
- public override int GetStreamCount(ref Int64 count)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetStreamCount(playerId, ref count);
- }
- public override int GetStreamInfo(Int64 index, ref PlayerStreamInfo info)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetStreamInfo(playerId, index, ref info);
- }
- public override int SetLoopCount(int loopCount)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetLoopCount(playerId, loopCount);
- }
- public override int SetPlaybackSpeed(int speed)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetPlaybackSpeed(playerId, speed);
- }
- public override int SelectAudioTrack(int index)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SelectAudioTrack(playerId, index);
- }
- public override int SetPlayerOption(string key, int value)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetPlayerOption(playerId, key, value);
- }
- public override int SetPlayerOption(string key, string value)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetPlayerOption(playerId, key, value);
- }
- public override int TakeScreenshot(string filename)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.TakeScreenshot(playerId, filename);
- }
- public override int SelectInternalSubtitle(int index)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SelectInternalSubtitle(playerId, index);
- }
- public override int SetExternalSubtitle(string url)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetExternalSubtitle(playerId, url);
- }
- public override MEDIA_PLAYER_STATE GetState()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return MEDIA_PLAYER_STATE.PLAYER_STATE_DO_NOTHING_INTERNAL;
- }
- return _mediaPlayerImpl.GetState(playerId);
- }
- public override int Mute(bool muted)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.Mute(playerId, muted);
- }
- public override int GetMute(ref bool muted)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetMute(playerId, ref muted);
- }
- public override int AdjustPlayoutVolume(int volume)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.AdjustPlayoutVolume(playerId, volume);
- }
- public override int GetPlayoutVolume(ref int volume)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetPlayoutVolume(playerId, ref volume);
- }
- public override int AdjustPublishSignalVolume(int volume)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.AdjustPublishSignalVolume(playerId, volume);
- }
- public override int GetPublishSignalVolume(ref int volume)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetPublishSignalVolume(playerId, ref volume);
- }
- public override int SetView()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetView(playerId);
- }
- public override int SetRenderMode(RENDER_MODE_TYPE renderMode)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetRenderMode(playerId, renderMode);
- }
- public override int SetAudioDualMonoMode(AUDIO_DUAL_MONO_MODE mode)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetAudioDualMonoMode(playerId, mode);
- }
- public override string GetPlayerSdkVersion()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return null;
- }
- return _mediaPlayerImpl.GetPlayerSdkVersion(playerId);
- }
- public override string GetPlaySrc()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return null;
- }
- return _mediaPlayerImpl.GetPlaySrc(playerId);
- }
- public override int SetAudioPitch(int pitch)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetAudioPitch(playerId, pitch);
- }
- public override int SetSpatialAudioParams(SpatialAudioParams spatial_audio_params)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SetSpatialAudioParams(playerId, spatial_audio_params);
- }
- public override int OpenWithAgoraCDNSrc(string src, Int64 startPos)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.OpenWithAgoraCDNSrc(playerId, src, startPos);
- }
- public override int GetAgoraCDNLineCount()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetAgoraCDNLineCount(playerId);
- }
- public override int SwitchAgoraCDNLineByIndex(int index)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SwitchAgoraCDNLineByIndex(playerId, index);
- }
- public override int GetCurrentAgoraCDNIndex()
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.GetCurrentAgoraCDNIndex(playerId);
- }
- public override int EnableAutoSwitchAgoraCDN(bool enable)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.EnableAutoSwitchAgoraCDN(playerId, enable);
- }
- public override int RenewAgoraCDNSrcToken(string token, Int64 ts)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.RenewAgoraCDNSrcToken(playerId, token, ts);
- }
- public override int SwitchAgoraCDNSrc(string src, bool syncPts = false)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SwitchAgoraCDNSrc(playerId, src, syncPts);
- }
- public override int SwitchSrc(string src, bool syncPts = true)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.SwitchSrc(playerId, src, syncPts);
- }
- public override int PreloadSrc(string src, Int64 startPos)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.PreloadSrc(playerId, src, startPos);
- }
- public override int PlayPreloadedSrc(string src)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.PlayPreloadedSrc(playerId, src);
- }
- public override int UnloadSrc(string src)
- {
- if (_rtcEngineInstance == null || _mediaPlayerImpl == null)
- {
- return ErrorCode;
- }
- return _mediaPlayerImpl.UnloadSrc(playerId, src);
- }
- }
- }
|