Esempio n. 1
0
        /// <summary>
        /// Initializes Player.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInitialized(EventArgs e)
        {
            Application.Current.DispatcherUnhandledException += (Sender, Args) =>
            {
                using (FileStream FS = File.Create("exception.txt"))
                    using (TextWriter Writer = new StreamWriter(FS))
                        WriteExceptionDetails(Args.Exception, Writer);

                MessageBox.Show("An exception has been encountered. The exact details have been saved in exception.txt. Please contact the developer and hand them this file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
#if !DEBUG
                Args.Handled = true;
#endif
                Application.Current.Shutdown( );
            };

            Player = new ViderePlayer(new WindowData {
                Window = this, MediaControlsContainer = MediaControlsContainer, MediaPlayer = new VLCPlayer(MediaArea.MediaPlayer), MediaArea = MediaArea
            });

            MediaComponent mediaComponent = Player.GetComponent <MediaComponent>( );
            mediaComponent.OnMediaLoaded       += OnOnMediaLoaded;
            mediaComponent.OnMediaUnloaded     += OnOnMediaUnloaded;
            mediaComponent.OnMediaFailedToLoad += MediaComponentOnOnMediaFailedToLoad;

            WindowButtonCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never;
            RightWindowCommandsOverlayBehavior  = WindowCommandsOverlayBehavior.Never;
            LeftWindowCommandsOverlayBehavior   = WindowCommandsOverlayBehavior.Never;

            Client = new Client(UserAgent);

            Application.Current.Exit += (sender, args) =>
            {
                Settings.Default.SubtitleTimeOffset = 0;
                Settings.Default.Save( );
            };

            KeyDown += OnKeyDown;

            StateComponent  stateComponent  = Player.GetComponent <StateComponent>( );
            ScreenComponent screenComponent = Player.GetComponent <ScreenComponent>( );

            stateComponent.OnStateChanged += (Sender, Args) =>
            {
                switch (Args.State)
                {
                case StateComponent.PlayerState.Playing:
                    screenComponent.DisableSleeping( );
                    break;

                case StateComponent.PlayerState.Paused:
                case StateComponent.PlayerState.Stopped:
                    screenComponent.EnableSleeping( );
                    break;
                }
            };

            string[] cmdArgs = Environment.GetCommandLineArgs( );
            if (cmdArgs.Length > 1)
            {
                Player.GetComponent <MediaComponent>( ).LoadMedia(cmdArgs[1]);
            }

            base.OnInitialized(e);

            (( OpenSubtitlesControl )this.OSFlyout.Content).InitWindow(this);
        }