Пример #1
0
        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;
        }
Пример #2
0
        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;
        }
Пример #3
0
        /// <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();
            }
        }
Пример #4
0
        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;
        }
Пример #5
0
        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 Awake()
    {
                #if UNITY_ANDROID
        videoView = new IMediaPlayerAndroid();
                #elif UNITY_IPHONE
        videoView = new IMediaPlayerIOS();
                #else
        videoView = new IMediaPlayerNull();
                #endif

        callback = null;
    }
Пример #8
0
        public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback, Guid accessToken)
        {
            this.accessControl.VerifyAccess(accessToken);

            this.audioPlayer.RegisterVideoPlayerCallback(videoPlayerCallback);
        }
 public void setCallback( IMediaPlayerCallback _callback )
 {
     callback = _callback;
 }
Пример #10
0
 public void RegisterVideoPlayer(IMediaPlayerCallback callback)
 {
     this.library.RegisterVideoPlayerCallback(callback, this.accessToken);
 }
Пример #11
0
 public void RegisterVideoPlayer(IMediaPlayerCallback callback)
 {
     this.library.RegisterVideoPlayerCallback(callback, this.accessToken);
 }
Пример #12
0
        public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback, Guid accessToken)
        {
            this.accessControl.VerifyAccess(accessToken);

            this.audioPlayer.RegisterVideoPlayerCallback(videoPlayerCallback);
        }
 public void setCallback(IMediaPlayerCallback _callback)
 {
     callback = _callback;
 }
Пример #14
0
 public void RegisterVideoPlayerCallback(IMediaPlayerCallback callback) => this.videoPlayerCallback = callback;
Пример #15
0
        /// <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();
            }
        }
Пример #16
0
 public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback)
 {
     this.videoPlayerCallback = videoPlayerCallback;
 }
Пример #17
0
 public LibraryBuilder WithAudioPlayer(IMediaPlayerCallback player)
 {
     this.audioPlayerCallback = player;
     return this;
 }
Пример #18
0
 public void RegisterVideoPlayerCallback(IMediaPlayerCallback videoPlayerCallback)
 {
     this.videoPlayerCallback = videoPlayerCallback;
 }
Пример #19
0
 public LibraryBuilder WithAudioPlayer(IMediaPlayerCallback player)
 {
     this.audioPlayerCallback = player;
     return(this);
 }