Ejemplo n.º 1
0
        /// <summary>
        /// Plays the file
        /// </summary>
        /// <param name="strFile">Filename</param>
        /// <returns>true, if playing has started</returns>
        public override bool Play(string strFile)
        {
            bool result;
            bool controlAdded = false;

            try
            {
                if (strFile.EndsWith(".mplayer"))
                {
                    strFile = strFile.Remove(strFile.LastIndexOf(".mplayer"));
                }
                if (strFile.StartsWith("ZZZZ:"))
                {
                    strFile = "rtsp:" + strFile.Remove(0, 5);
                }
                bool isVideo = _configManager.HasFileOrStreamVideo(strFile);
                _currentFile = strFile;
                InitSystem(isVideo);
                _mplayerProcess        = _configManager.CreateProcessForFileName(strFile, _videoHandler.GetVideoHandle());
                _videoHandler.HasVideo = isVideo;
                if (isVideo)
                {
                    _isVisible = true;
                    _videoHandler.AddVideoWindowToForm();
                    controlAdded = true;
                }
                else
                {
                    _isVisible = false;
                }
                _exitHandler            = MplayerProcessExited;
                _mplayerProcess.Exited += _exitHandler;
                _mplayerProcess.Start();
                _dataReceivedHandler = MplayerProcessOutputDataReceived;
                _mplayerProcess.OutputDataReceived += _dataReceivedHandler;
                _mplayerProcess.BeginOutputReadLine();
                _input = _mplayerProcess.StandardInput;
                result = true;
            }
            catch (Exception e)
            {
                Log.Info("MPlayer Error: " + e.Message);
                Log.Error(e);
                if (controlAdded)
                {
                    _videoHandler.RemoveVideoWindowToForm();
                }
                _currentFile = String.Empty;
                _playState   = PlayState.Ended;
                result       = false;
                _osdHandler.Dispose();
            }
            return(result);
        }