internal AudioPlayer() { this.audioPlayerCallback = new DummyMediaPlayerCallback(); this.videoPlayerCallback = new DummyMediaPlayerCallback(); this.currentCallback = new DummyMediaPlayerCallback(); this.finishSubscription = new SerialDisposable(); this.gate = new SemaphoreSlim(1, 1); this.playbackState = new BehaviorSubject<AudioPlayerState>(AudioPlayerState.None); this.PlaybackState = this.playbackState.DistinctUntilChanged(); this.loadedSong = new BehaviorSubject<Song>(null); this.TotalTime = this.loadedSong.Select(x => x == null ? TimeSpan.Zero : x.Duration); this.currentTimeChangedFromOuter = new Subject<TimeSpan>(); var conn = Observable.Interval(TimeSpan.FromMilliseconds(300), RxApp.TaskpoolScheduler) .CombineLatest(this.PlaybackState, (l, state) => state) .Where(x => x == AudioPlayerState.Playing) .Select(_ => this.CurrentTime) .Merge(this.currentTimeChangedFromOuter) .DistinctUntilChanged(x => x.TotalSeconds) .Publish(TimeSpan.Zero); conn.Connect(); this.CurrentTimeChanged = conn; }
internal AudioPlayer() { this.audioPlayerCallback = new DummyMediaPlayerCallback(); this.videoPlayerCallback = new DummyMediaPlayerCallback(); this.currentCallback = new DummyMediaPlayerCallback(); this.finishSubscription = new SerialDisposable(); this.gate = new SemaphoreSlim(1, 1); this.playbackState = new BehaviorSubject <AudioPlayerState>(AudioPlayerState.None); this.PlaybackState = this.playbackState.DistinctUntilChanged(); this.loadedSong = new BehaviorSubject <Song>(null); this.TotalTime = this.loadedSong.Select(x => x == null ? TimeSpan.Zero : x.Duration); this.currentTimeChangedFromOuter = new Subject <TimeSpan>(); var conn = Observable.Interval(TimeSpan.FromMilliseconds(300), RxApp.TaskpoolScheduler) .CombineLatest(this.PlaybackState, (l, state) => state) .Where(x => x == AudioPlayerState.Playing) .Select(_ => this.CurrentTime) .Merge(this.currentTimeChangedFromOuter) .DistinctUntilChanged(x => x.TotalSeconds) .Publish(TimeSpan.Zero); conn.Connect(); this.CurrentTimeChanged = conn; }
/// <summary> /// Loads the specified song asynchronously into the audio player. /// </summary> /// <param name="song">The song to load and play.</param> /// <exception cref="ArgumentNullException"><paramref name="song" /> is <c>null</c></exception> /// <exception cref="SongLoadException">An error occured while loading the song.</exception> internal async Task LoadAsync(Song song) { if (song == null) { throw new ArgumentNullException("song"); } await this.gate.WaitAsync(); this.finishSubscription.Disposable = Disposable.Empty; try { await this.currentCallback.StopAsync(); await this.SetPlaybackStateAsync(AudioPlayerState.Stopped); } // If the stop method throws an exception and we don't swallow it, we can never reassign // the current callback catch (Exception ex) { this.Log().ErrorException("Failed to stop current media player callback " + this.currentCallback, ex); } if (this.loadedSong.Value != null && !this.loadedSong.Value.IsVideo && this.disposeCurrentAudioCallback && this.currentCallback is IDisposable) { ((IDisposable)this.currentCallback).Dispose(); } this.disposeCurrentAudioCallback = false; this.loadedSong.OnNext(song); this.currentCallback = song.IsVideo ? this.videoPlayerCallback : this.audioPlayerCallback; try { await this.currentCallback.LoadAsync(new Uri(this.loadedSong.Value.PlaybackPath)); this.finishSubscription.Disposable = this.currentCallback.Finished.FirstAsync() .SelectMany(_ => this.Finished().ToObservable()) .Subscribe(); } catch (Exception ex) { throw new SongLoadException("Could not load song", ex); } finally { this.gate.Release(); } }
public void RegisterAudioPlayerCallback(IMediaPlayerCallback audioPlayerCallback) { if (this.disposeCurrentAudioCallback && this.audioPlayerCallback is IDisposable) { ((IDisposable)this.audioPlayerCallback).Dispose(); this.disposeCurrentAudioCallback = false; } this.audioPlayerCallback = audioPlayerCallback; this.disposeCurrentAudioCallback = true; }
public void Awake() { #if UNITY_ANDROID videoView = new IMediaPlayerAndroid(); #elif UNITY_IPHONE videoView = new IMediaPlayerIOS(); #else videoView = new IMediaPlayerNull(); #endif callback = null; }
public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback, Guid accessToken) { this.accessControl.VerifyAccess(accessToken); this.audioPlayer.RegisterVideoPlayerCallback(videoPlayerCallback); }
public void setCallback( IMediaPlayerCallback _callback ) { callback = _callback; }
public void RegisterVideoPlayer(IMediaPlayerCallback callback) { this.library.RegisterVideoPlayerCallback(callback, this.accessToken); }
public void setCallback(IMediaPlayerCallback _callback) { callback = _callback; }
public void RegisterVideoPlayerCallback(IMediaPlayerCallback callback) => this.videoPlayerCallback = callback;
/// <summary> /// Loads the specified song asynchronously into the audio player. /// </summary> /// <param name="song">The song to load and play.</param> /// <exception cref="ArgumentNullException"><paramref name="song" /> is <c>null</c></exception> /// <exception cref="SongLoadException">An error occured while loading the song.</exception> internal async Task LoadAsync(Song song) { if (song == null) throw new ArgumentNullException("song"); await this.gate.WaitAsync(); this.finishSubscription.Disposable = Disposable.Empty; try { await this.currentCallback.StopAsync(); await this.SetPlaybackStateAsync(AudioPlayerState.Stopped); } // If the stop method throws an exception and we don't swallow it, we can never reassign // the current callback catch (Exception ex) { this.Log().ErrorException("Failed to stop current media player callback " + this.currentCallback, ex); } if (this.loadedSong.Value != null && !this.loadedSong.Value.IsVideo && this.disposeCurrentAudioCallback && this.currentCallback is IDisposable) { ((IDisposable)this.currentCallback).Dispose(); } this.disposeCurrentAudioCallback = false; this.loadedSong.OnNext(song); this.currentCallback = song.IsVideo ? this.videoPlayerCallback : this.audioPlayerCallback; try { await this.currentCallback.LoadAsync(new Uri(this.loadedSong.Value.PlaybackPath)); this.finishSubscription.Disposable = this.currentCallback.Finished.FirstAsync() .SelectMany(_ => this.Finished().ToObservable()) .Subscribe(); } catch (Exception ex) { throw new SongLoadException("Could not load song", ex); } finally { this.gate.Release(); } }
public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback) { this.videoPlayerCallback = videoPlayerCallback; }
public LibraryBuilder WithAudioPlayer(IMediaPlayerCallback player) { this.audioPlayerCallback = player; return this; }
public LibraryBuilder WithAudioPlayer(IMediaPlayerCallback player) { this.audioPlayerCallback = player; return(this); }