Beispiel #1
0
        void PlaybackOperationEnded(bool countAsWatched, VM_AnimeEpisode_User ep)
        {
            try
            {
                if (ep == null)
                {
                    return;
                }

                if (ep != null)
                {
                    ep.IncrementEpisodeStats(Shoko.Models.Enums.StatCountType.Stopped);
                }

                //save watched status
                if (countAsWatched || ep.IsWatched())
                {
                    //MPTVSeriesLog.Write("This episode counts as watched");
                    if (countAsWatched)
                    {
                        BaseConfig.MyAnimeLog.Write("Marking episode as watched: " + ep.EpisodeNumberAndNameWithType);
                        MarkEpisodeAsWatched(ep);
                    }
                }
                traktScrobbleEnabled = false;
                TraktScrobble(ScrobblePlayingStatus.Stop);

                SetGUIProperties(true); // clear GUI Properties
            }
            catch (Exception e)
            {
                BaseConfig.MyAnimeLog.Write("Error in VideoHandler.PlaybackOperationEnded: {0}", e.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initiates Playback of m_currentEpisode[DBEpisode.cFilename] and calls Fullscreen Window
        /// </summary>
        /// <param name="timeMovieStopped">Resumepoint of Movie, 0 or negative for Start from Beginning</param>
        /// <param name="audioLanguage">Audio language to be used, use null for system default</param>
        /// <param name="subLanguage">Subtitle language to be used, use null for system default or an empty string for no subs</param>
        ///
        bool Play(int timeMovieStopped, String audioLanguage, String subLanguage)
        {
            bool result = false;

            try
            {
                // sometimes it takes up to 30+ secs to go to fullscreen even though the video is already playing
                // lets force fullscreen here
                // note: MP might still be unresponsive during this time, but at least we are in fullscreen and can see video should this happen
                // I haven't actually found out why it happens, but I strongly believe it has something to do with the video database and the player doing something in the background
                // (why does it do anything with the video database.....i just want it to play a file and do NOTHING else!)

                // TEMPORARY FIX
                // If file isn't local show dialog and return as streaming isn't fully working yet
                if (current.IsLocalOrStreaming() == true)
                {
                    GUIDialogOK dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOk.SetHeading(Translation.FileNotFoundLocally);
                    dlgOk.SetLine(1, Translation.StreamingNotSupported);
                    dlgOk.SetLine(2, current.FileName);

                    if (dlgOk.IsConfirmed)
                    {
                        return(false);
                    }
                    return(false);
                }

                if (current.IsLocalOrStreaming() == true)
                {
                    if (BaseConfig.Settings.AskBeforeStartStreamingPlayback)
                    {
                        GUIDialogYesNo dlgYesNo =
                            (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

                        if (null != dlgYesNo)
                        {
                            dlgYesNo.SetHeading(Translation.UseStreaming);
                            dlgYesNo.SetLine(1, Translation.FileNotFoundLocally);
                            dlgYesNo.SetLine(2, current.FileName);
                            dlgYesNo.SetDefaultToYes(true);
                            dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);

                            if (!dlgYesNo.IsConfirmed)
                            {
                                return(false);
                            }
                        }
                    }

                    GUIGraphicsContext.IsFullScreenVideo = true;
                    GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO);

                    // Start Listening to any External Player Events
                    listenToExternalPlayerEvents = true;
                    CreateSubsOnTempIfNecesary(current.Media);

                    IPlayerFactory prevfactory = g_Player.Factory;
                    g_Player.Factory = PlayerFactory.Instance;

                    timeMovieStopped = 0;

                    //FIX MEDIAPORTAL 1 Bug checking for mediainfo.
                    g_Player._mediaInfo = new MediaInfoWrapper("donoexists");
                    //************************//
                    currentUri       = current.Uri;
                    g_Player.Factory = prevfactory;
                }
                else
                {
                    GUIGraphicsContext.IsFullScreenVideo = true;
                    GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO);

                    // Start Listening to any External Player Events
                    listenToExternalPlayerEvents = true;
                    currentUri = current.Uri;
                }

                if (string.IsNullOrEmpty(current.Uri))
                {
                    return(false);
                }

                g_Player.Play(current.Uri, g_Player.MediaType.Video);

                // Stop Listening to any External Player Events
                listenToExternalPlayerEvents = false;

                //set properties
                if (g_Player.Playing)
                {
                    g_Player.Pause();

                    //set audio language
                    if (string.IsNullOrEmpty(audioLanguage))
                    {
                        audioLanguage = DefaultAudioLanguage;
                    }
                    if (audioLanguage != "<file>")
                    {
                        string requestedLanguage = MediaPortal.Util.Utils.TranslateLanguageString(audioLanguage);
                        for (int index = 0; index < g_Player.AudioStreams; index++)
                        {
                            string lang = g_Player.AudioLanguage(index);
                            if (MediaPortal.Util.Utils.TranslateLanguageString(lang)
                                .Equals(requestedLanguage, StringComparison.OrdinalIgnoreCase))
                            {
                                g_Player.Player.CurrentAudioStream = index;
                                break;
                            }
                        }
                    }

                    //set sub language
                    g_Player.Player.EnableSubtitle = true;
                    if (string.IsNullOrEmpty(subLanguage))
                    {
                        subLanguage = DefaultSubtitleLanguage;
                    }
                    if (subLanguage == "<none>")
                    {
                        //no subs
                        g_Player.Player.EnableSubtitle = false;
                    }
                    else if (subLanguage != "<file>")
                    {
                        //selected sub
                        string requestedLanguage = MediaPortal.Util.Utils.TranslateLanguageString(subLanguage);
                        for (int index = 0; index < g_Player.SubtitleStreams; index++)
                        {
                            string lang = g_Player.SubtitleLanguage(index);
                            if (MediaPortal.Util.Utils.TranslateLanguageString(lang)
                                .Equals(requestedLanguage, StringComparison.OrdinalIgnoreCase))
                            {
                                g_Player.Player.CurrentSubtitleStream = index;
                                break;
                            }
                        }
                    }

                    // tell player where to resume
                    if (timeMovieStopped > 0)
                    {
                        g_Player.SeekAbsolute(timeMovieStopped);
                    }

                    if (curEpisode != null)
                    {
                        curEpisode.IncrementEpisodeStats(Shoko.Models.Enums.StatCountType.Played);
                    }

                    g_Player.Pause();

                    traktScrobbleEnabled = true;
                    Thread t = new Thread(TraktScrobbleThread);
                    t.IsBackground = true;
                    t.Start();
                }
            }
            catch (Exception e)
            {
                BaseConfig.MyAnimeLog.Write("Error in VideoHandler.Play: {0}", e);
                result = false;
            }
            return(result);
        }