Ejemplo n.º 1
0
        private async Task SetMediaFile(IMediaItem media)
        {
            if (media.VlcMedia != null)
            {
                CurrentMedia = media.VlcMedia;
            }
            else
            {
                var mrl_fromType = media.GetMrlAndFromType();
                LogHelper.Log("SetMRL: " + mrl_fromType.Item2);
                if (Instance == null)
                {
                    await Initialize();
                }
                await PlayerInstanceReady.Task;

                if (!PlayerInstanceReady.Task.Result)
                {
                    LogHelper.Log($"Couldn't play media {media.Name} as VLC failed to init");
                    return;
                }

                CurrentMedia = new Media(Instance, mrl_fromType.Item2, mrl_fromType.Item1);
            }

            // Hardware decoding
            CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-hw=none" : ":avcodec-hw=d3d11va");
            CurrentMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-threads=0" : ":avcodec-threads=1");
            var pos = await FetchPreviousPosition(media);

            CurrentMedia.addOption($":start-time={pos}");

            if (_mediaPlayer == null)
            {
                _mediaPlayer = new MediaPlayer(CurrentMedia);
                var em = _mediaPlayer.eventManager();

                em.OnBuffering        += Playback_MediaBuffering;
                em.OnStopped          += OnStopped;
                em.OnPlaying          += OnPlaying;
                em.OnPaused           += OnPaused;
                em.OnTimeChanged      += Playback_MediaTimeChanged;
                em.OnEndReached       += OnEndReached;
                em.OnEncounteredError += Playback_MediaFailed;
                em.OnLengthChanged    += Playback_MediaLengthChanged;
                em.OnTrackAdded       += OnTrackAdded;
                em.OnTrackDeleted     += OnTrackDeleted;
                em.OnPlaying          += Playback_MediaPlaying;
                em.OnPaused           += Playback_MediaPaused;
                em.OnOpening          += Playback_Opening;
            }
            else
            {
                _mediaPlayer.setMedia(CurrentMedia);
            }
            _mediaPlayer.outputDeviceSet(AudioClient.audioClient());
            SetEqualizer(Locator.SettingsVM.Equalizer);
        }
Ejemplo n.º 2
0
        public async Task SetMediaFile(IMediaItem media)
        {
            Media vlcMedia = null;

            if (media.VlcMedia != null)
            {
                vlcMedia = media.VlcMedia;
            }
            else
            {
                var mrl_fromType = media.GetMrlAndFromType();
                LogHelper.Log("SetMRL: " + mrl_fromType.Item2);
                if (Instance == null)
                {
                    await Initialize();
                }
                await PlayerInstanceReady.Task;

                if (!PlayerInstanceReady.Task.Result)
                {
                    LogHelper.Log($"Couldn't play media {media.Name} as VLC failed to init");
                    return;
                }

                vlcMedia = new Media(Instance, mrl_fromType.Item2, mrl_fromType.Item1);
            }

            // Hardware decoding
            vlcMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-hw=none" : ":avcodec-hw=d3d11va");
            vlcMedia.addOption(!Locator.SettingsVM.HardwareAccelerationEnabled ? ":avcodec-threads=0" : ":avcodec-threads=1");

            MediaPlayer = new MediaPlayer(vlcMedia);
            LogHelper.Log("PLAYWITHVLC: MediaPlayer instance created");
            MediaPlayer.outputDeviceSet(AudioClient.audioClient());
            SetEqualizer(Locator.SettingsVM.Equalizer);
            var em = MediaPlayer.eventManager();

            em.OnOpening   += Em_OnOpening;
            em.OnBuffering += EmOnOnBuffering;
            em.OnStopped   += EmOnOnStopped;
            em.OnPlaying   += OnPlaying;
            em.OnPaused    += OnPaused;
            if (TimeChanged != null)
            {
                em.OnTimeChanged += TimeChanged;
            }
            em.OnEndReached       += EmOnOnEndReached;
            em.OnEncounteredError += em_OnEncounteredError;
            em.OnLengthChanged    += em_OnLengthChanged;
        }