CodeImp.Gluon.MediaPlayerDisplayPanel.PlayFile C# (CSharp) Метод

PlayFile() приватный Метод

private PlayFile ( string filepathname, int startpos ) : void
filepathname string
startpos int
Результат void
        private void PlayFile(string filepathname, int startpos)
        {
            if(!isplaying)
                General.Power.DisablePowerSave();

            // Show the last two directories the file is in
            string displayfilepath = Path.GetFullPath(filepathname);
            string[] pathparts = displayfilepath.Split(Path.DirectorySeparatorChar);
            string displaypathtitle = "";
            if(pathparts.Length > 2)
                displaypathtitle += pathparts[pathparts.Length - 3] + " - ";
            if(pathparts.Length > 1)
                displaypathtitle += pathparts[pathparts.Length - 2] + " - ";
            itemtitle.Text = displaypathtitle + Path.GetFileNameWithoutExtension(filepathname);

            timelabel.Visible = false;
            totaltimelabel.Visible = false;
            positionlabel.Visible = false;
            currentmediapos = 0;
            medialength = 0;
            seekbar.MaxValue = 100;
            seekbar.MinValue = 0;
            seekbar.Value = 0;
            seekbar.Visible = true;
            stopbutton.Visible = true;
            pausebutton.StopInfoFlash();
            pausebutton.Text = "Pause";
            pausebutton.Visible = true;
            stopintended = false;
            isplaying = true;
            ispaused = false;
            playingfile = filepathname;
            player.close();

            // Subtitle support!
            try
            {
                string fileext = Path.GetExtension(filepathname);
                string filewithoutext = filepathname.Substring(0, filepathname.Length - fileext.Length);
                string subtitlefile = filewithoutext + ".srt";
                if(File.Exists(subtitlefile))
                {
                    // Copy subtitles to the subtitles location
                    File.Copy(subtitlefile, General.Settings.SubtitlesFile, true);
                }
                else
                {
                    // Make the subtitles file empty
                    File.WriteAllText(General.Settings.SubtitlesFile, "");
                }
            }
            catch(Exception e)
            {
                General.WriteLogLine(e.GetType().Name + " while creating subtitles file: " + e.Message);
            }

            if(onscreen)
            {
                // Send message
                onscreeninfo.Visible = true;
                MEDIASTARTDATA startdata = new MEDIASTARTDATA();
                startdata.muxfilename = muxingfile;
                startdata.filename = filepathname;
                startdata.startpos = startpos;
                InterProcess.SendMessage(InterProcess.MSG_MEDIA_START, startdata);
            }
            else
            {
                player.URL = filepathname;

                // Wait for the player to load the file
                while((player.playState == WMPPlayState.wmppsBuffering) ||
                      (player.playState == WMPPlayState.wmppsTransitioning) ||
                      (player.playState == WMPPlayState.wmppsReady))
                {
                    Application.DoEvents();
                }

                if(!string.IsNullOrEmpty(muxingfile))
                {
                    player.Visible = false;
                    muxplayer.Visible = true;

                    // Don't interrupt the muxed video if not needed
                    if(muxingfile != muxingfileplaying)
                    {
                        muxingfileplaying = muxingfile;
                        muxplayer.URL = muxingfile;

                        // Wait for the player to load the file
                        while((player.playState == WMPPlayState.wmppsBuffering) ||
                              (player.playState == WMPPlayState.wmppsTransitioning) ||
                              (player.playState == WMPPlayState.wmppsReady))
                        {
                            Application.DoEvents();
                        }

                        // Play!
                        muxplayer.Ctlcontrols.play();
                    }
                }
                else
                {
                    player.Visible = true;
                    muxplayer.Visible = false;
                    muxplayer.close();
                    muxingfileplaying = "";
                }

                // Play!
                player.Ctlcontrols.currentPosition = (double)startpos;
                player.Ctlcontrols.play();

                ShowMediaInfo(startpos, (int)player.currentMedia.duration);
                updatetimer.Start();
            }
        }