private void MediaLoading(object sender, MediaLoadingEventArgs e)
        {
            if (!Settings.EnableAutoDownloader)
            {
                return;
            }
            if (HasExistingSubtitle(e.Filename))
            {
                return;
            }
            try
            {
                List <Subtitle> subList;
                using (new HourGlass())
                {
                    subList = m_Downloader.GetSubtitles(e.Filename);
                }
                if (subList == null || subList.Count == 0)
                {
                    return; // Opensubtitles messagebox is annoying #44 https://github.com/zachsaw/MPDN_Extensions/issues/44
                }
                subList.Sort((a, b) => String.Compare(a.Lang, b.Lang, CultureInfo.CurrentUICulture, CompareOptions.StringSort));

                m_Form.SetSubtitles(subList, Settings.PreferedLanguage);
                m_Form.ShowDialog(PlayerControl.Form);
            }
            catch (InternetConnectivityException)
            {
                Trace.WriteLine("OpenSubtitles: Failed to access OpenSubtitles.org (InternetConnectivityException)");
            }
            catch (Exception)
            {
                Trace.WriteLine("OpenSubtitles: General exception occurred while trying to get subtitles");
            }
        }
Exemplo n.º 2
0
        private void OnMediaLoading(object sender, MediaLoadingEventArgs e)
        {
            var filename = e.Filename;

            if (!IsRarFile(filename))
            {
                return;
            }

            e.CustomSourceFilter = graph =>
            {
                try
                {
                    return(new RarFileSource(m_RarFileSourceFilter, graph, filename));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                    return(null);
                }
            };
        }
Exemplo n.º 3
0
        private static void OnMediaLoading(object sender, MediaLoadingEventArgs e)
        {
            var filename = e.Filename;

            if (!IsYouTubeSource(filename))
            {
                return;
            }

            e.CustomSourceFilter = graph =>
            {
                try
                {
                    return(new YouTubeSource(graph, filename));
                }
                catch (Exception ex)
                {
                    // User may not have 3DYD YouTubeSource filter installed
                    Trace.WriteLine(ex);
                    return(null);
                }
            };
        }
Exemplo n.º 4
0
 private void OnMediaLoading(object sender, MediaLoadingEventArgs e)
 {
     m_Timer.Stop();
     m_Form.HandleMediaLoading(e);
 }
        async Task PlaybackLoadingAsync(MediaLoadingEventArgs mediaLoadingEventArgs)
        {
            // ReSharper disable once PossiblyMistakenUseOfParamsMethod
            var mediaLoadingCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_unloadCancellationTokenSource.Token);

            var oldTokenSource = Interlocked.Exchange(ref _mediaLoadingCancellationTokenSource, mediaLoadingCancellationTokenSource);

            if (null != oldTokenSource)
            {
                oldTokenSource.CancelDisposeSafe();
            }

            var source = mediaLoadingEventArgs.Source;

            if (null == source)
            {
                return;
            }

            MediaPlayerDeferral deferral = null;

            try
            {
                deferral = mediaLoadingEventArgs.DeferrableOperation.GetDeferral();

                if (deferral.CancellationToken.IsCancellationRequested)
                {
                    return;
                }

                using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(deferral.CancellationToken, mediaLoadingCancellationTokenSource.Token))
                {
                    var cancellationToken = linkedTokenSource.Token;

                    PlaybackSession playbackSession;

                    using (await _asyncLock.LockAsync(cancellationToken).ConfigureAwait(false))
                    {
                        playbackSession = _playbackSession;

                        if (null != playbackSession)
                        {
                            await playbackSession.StopAsync(cancellationToken);

                            playbackSession = _playbackSession;

                            if (null != playbackSession)
                            {
                                Debug.WriteLine("StreamingMediaPlugin MediaLoading non-null _playbackSession");

                                return;
                            }
                        }

                        if (string.Equals(source.Scheme, "stop", StringComparison.OrdinalIgnoreCase))
                        {
                            Debug.WriteLine("StreamingMediaPlugin MediaLoading stop");
                            return;
                        }

                        var passThrough = StreamingMediaSettings.Parameters.IsPassThrough;

                        if (null != passThrough)
                        {
                            if (passThrough(source))
                            {
                                Debug.WriteLine("StreamingMediaPlugin.PlayerOnMediaLoading() passing through " + source);

                                deferral.Complete();
                                deferral = null;

                                return;
                            }
                        }

                        playbackSession = new PlaybackSession(InitializeMediaStream());

                        var playTask = PlayAsync(playbackSession, source, cancellationToken);

                        TaskCollector.Default.Add(playTask, "StreamingMediaPlugin MediaLoading playTask");
                    }

                    mediaLoadingEventArgs.MediaStreamSource = await playbackSession.GetMediaSourceAsync(cancellationToken).ConfigureAwait(false);

                    mediaLoadingEventArgs.Source = null;

                    //Debug.WriteLine("StreamingMediaPlugin MediaLoading deferral.Complete()");
                    deferral.Complete();
                    deferral = null;
                }
            }
            catch (OperationCanceledException)
            { }
            catch (Exception ex)
            {
                Debug.WriteLine("StreamingMediaPlugin.PlayerOnMediaLoading() failed: " + ex.Message);
            }
            finally
            {
                if (null != deferral)
                {
                    Debug.WriteLine("StreamingMediaPlugin MediaLoading deferral.Cancel()");
                    deferral.Cancel();
                }
            }
        }
Exemplo n.º 6
0
        private static void OnMediaLoading(object sender, MediaLoadingEventArgs e)
        {
            if (!IsYouTubeSource(e.Filename))
                return;

            e.CustomSourceFilter = graph =>
            {
                try
                {
                    return new YouTubeSource(graph, e.Filename);
                }
                catch (Exception ex)
                {
                    // User may not have 3DYD YouTubeSource filter installed
                    Trace.WriteLine(ex);
                    return null;
                }
            };
        }