private void HandleDvdEvent() { int hr = 0; // Make sure that we don't access the media event interface // after it has already been released. if (_mediaEventEx == null) return; try { EventCode evCode; IntPtr evParam1, evParam2; // Process all queued events while (_mediaEventEx.GetEvent(out evCode, out evParam1, out evParam2, 0) == 0) { _logger.Debug("Received media event code {0}", evCode); switch (evCode) { case EventCode.DvdCurrentHmsfTime: byte[] ati = BitConverter.GetBytes(evParam1.ToInt32()); var currnTime = new DvdHMSFTimeCode(); currnTime.bHours = ati[0]; currnTime.bMinutes = ati[1]; currnTime.bSeconds = ati[2]; currnTime.bFrames = ati[3]; //UpdateMainTitle(); break; case EventCode.DvdChapterStart: //currnChapter = evParam1.ToInt32(); //UpdateMainTitle(); break; case EventCode.DvdTitleChange: //currnTitle = evParam1.ToInt32(); //UpdateMainTitle(); break; case EventCode.DvdDomainChange: //currnDomain = (DvdDomain)evParam1; //UpdateMainTitle(); break; case EventCode.DvdCmdStart: break; case EventCode.DvdCmdEnd: OnDvdCmdComplete(evParam1, evParam2); break; case EventCode.DvdStillOn: if (evParam1 == IntPtr.Zero) _dvdMenuMode = DvdMenuMode.Buttons; else _dvdMenuMode = DvdMenuMode.Still; break; case EventCode.DvdStillOff: if (_dvdMenuMode == DvdMenuMode.Still) _dvdMenuMode = DvdMenuMode.No; break; case EventCode.DvdButtonChange: if (evParam1.ToInt32() <= 0) _dvdMenuMode = DvdMenuMode.No; else _dvdMenuMode = DvdMenuMode.Buttons; break; case EventCode.DvdNoFpPgc: IDvdCmd icmd; if (_mDvdControl != null) hr = _mDvdControl.PlayTitle(1, DvdCmdFlags.None, out icmd); break; } // Free memory associated with callback, since we're not using it hr = _mediaEventEx.FreeEventParams(evCode, evParam1, evParam2); } } catch { } }
public override bool Play(string file) { if (String.IsNullOrEmpty(file)) return false; _currTime = new DvdHMSFTimeCode(); _UOPs = 0; _started = false; _visible = false; _positionX = 80; _positionY = 400; _width = 200; _height = 100; _videoWidth = 100; _videoHeight = 100; _speed = 1; _defaultAudioLanguage = null; _defaultSubtitleLanguage = null; _forceSubtitles = true; _aspectRatio = Geometry.Type.Normal; _speed = 1; _currentTime = 0; _visible = true; _started = false; _rotEntry = null; _volume = 100; _mouseMsg = new ArrayList(); VideoRendererStatistics.VideoState = VideoRendererStatistics.State.VideoPresent; if (!FirstPlayDvd(file)) { return false; } _fullScreen = true; _updateNeeded = true; GUIGraphicsContext.IsFullScreenVideo = true; /* GUIGraphicsContext.DX9Device.Clear( ClearFlags.Target, Color.Black, 1.0f, 0); try { // Show the frame on the primary surface. GUIGraphicsContext.DX9Device.Present(); } catch(DeviceLostException) { }*/ SetVideoWindow(); return true; }
private void UpdateDuration() { DvdHMSFTimeCode totaltime = new DvdHMSFTimeCode(); DvdTimeCodeFlags ulTimeCodeFlags; _dvdInfo.GetTotalTitleTime(totaltime, out ulTimeCodeFlags); _duration = new TimeSpan(totaltime.bHours, totaltime.bMinutes, totaltime.bSeconds).TotalSeconds; }
protected override void OnBeforeGraphRunning() { base.OnBeforeGraphRunning(); // first all automatically rendered pins FilterGraphTools.RenderOutputPins(_graphBuilder, _dvdbasefilter); // MSDN: "During the connection process, the Filter Graph Manager ignores pins on intermediate filters if the pin name begins with a tilde (~)." // then connect the skipped "~" output pins FilterGraphTools.RenderAllManualConnectPins(_graphBuilder); _currTime = new DvdHMSFTimeCode(); }
public override void SeekAbsolute(double newTime) { if (_state != PlayState.Init) { if (_mediaCtrl != null && _mediaPos != null) { if (newTime < 0.0d) { newTime = 0.0d; } if (newTime < Duration) { int hours = (int)(newTime / 3600d); newTime -= (hours * 3600); int minutes = (int)(newTime / 60d); newTime -= (minutes * 60); int seconds = (int)newTime; Log.Info("DVDPlayer:Seek to {0}:{1}:{2}", hours, minutes, seconds); DvdHMSFTimeCode timeCode = new DvdHMSFTimeCode(); timeCode.bHours = (byte)(hours & 0xff); timeCode.bMinutes = (byte)(minutes & 0xff); timeCode.bSeconds = (byte)(seconds & 0xff); timeCode.bFrames = 0; DvdPlaybackLocation2 loc; _currTitle = _dvdInfo.GetCurrentLocation(out loc); try { int hr = _dvdCtrl.PlayAtTime(timeCode, DvdCmdFlags.Block | DvdCmdFlags.Flush, out _cmdOption); if (hr != 0) { if (((uint)hr) == VFW_E_DVD_OPERATION_INHIBITED) { Log.Info("DVDPlayer:PlayAtTimeInTitle( {0}:{1:00}:{2:00}) not allowed at this point", hours, minutes, seconds); } else if (((uint)hr) == VFW_E_DVD_INVALIDDOMAIN) { Log.Info("DVDPlayer:PlayAtTimeInTitle( {0}:{1:00}:{2:00}) invalid domain", hours, minutes, seconds); } else { Log.Error("DVDPlayer:PlayAtTimeInTitle( {0}:{1:00}:{2:00}) failed:0x{3:X}", hours, minutes, seconds, hr); } } //SetDefaultLanguages(); Log.Info("DVDPlayer:Seek to {0}:{1}:{2} done", hours, minutes, seconds); } catch (Exception) { //sometimes we get a DivideByZeroException in _dvdCtrl.PlayAtTime() } } } } }
/// <summary> /// Converts a <see cref="DvdHMSFTimeCode"/> to <see cref="double"/> time stamp. /// </summary> /// <param name="timeCode">DvdHMSFTimeCode</param> /// <returns>Double</returns> private static double ToDouble(DvdHMSFTimeCode timeCode) { Double result = timeCode.bHours * 3600d; result += (timeCode.bMinutes * 60d); result += timeCode.bSeconds; return result; }
/// <summary> /// Calculates the duration. /// </summary> private void CalculateDuration() { DvdHMSFTimeCode totaltime = new DvdHMSFTimeCode(); DvdTimeCodeFlags ulTimeCodeFlags; _dvdInfo.GetTotalTitleTime(totaltime, out ulTimeCodeFlags); lock (SyncObj) _duration = ToDouble(totaltime); }
/// <summary> /// Converts a <see cref="TimeSpan"/> into a <see cref="DvdHMSFTimeCode"/>. /// </summary> /// <param name="newTime">TimeSpan to convert.</param> /// <returns><see cref="DvdHMSFTimeCode"/> instance.</returns> private static DvdHMSFTimeCode ToTimeCode(TimeSpan newTime) { int hours = newTime.Hours; int minutes = newTime.Minutes; int seconds = newTime.Seconds; DvdHMSFTimeCode timeCode = new DvdHMSFTimeCode { bHours = (byte) (hours & 0xff), bMinutes = (byte) (minutes & 0xff), bSeconds = (byte) (seconds & 0xff), bFrames = 0 }; return timeCode; }
void PlayTitle(DVDTitle title) { if (m_dvdCtrl == null) PreviewInit(); IDvdCmd cmd; DvdHMSFTimeCode time = new DvdHMSFTimeCode() { bSeconds = 10 }; m_dvdCtrl.PlayAtTimeInTitle(title.TitleNumber, time, DvdCmdFlags.SendEvents, out cmd); }
/// <summary> /// Here we extract out the new Dvd duration of /// the title currently being played /// </summary> private void SetTitleDuration() { var totalTime = new DvdHMSFTimeCode(); DvdTimeCodeFlags flags; int hr = m_dvdInfo.GetTotalTitleTime(totalTime, out flags); if (hr != 0) return; /* Convert the total time of the title to milliseconds */ Duration = (long)new TimeSpan(totalTime.bHours, totalTime.bMinutes, totalTime.bSeconds).TotalMilliseconds * MEDIA_TIME_TO_MILLISECONDS; }
public void ChangePosition(MouseEventArgs e) { if (mediaSeeking != null) { long currentPos = 0; long duration = 0; if (GetPositionAndDuration(out currentPos, out duration) >= 0) { long nPos = duration / pf.Width * e.X; ChangePosition(nPos, AMSeekingSeekingFlags.AbsolutePositioning); } } else if (dvdCtrl != null) { DvdHMSFTimeCode tc = new DvdHMSFTimeCode(); DvdTimeCodeFlags tf; int hr = dvdInfo.GetTotalTitleTime(tc, out tf); if (hr == 0) { TimeSpan tsDuration = new TimeSpan(tc.bHours, tc.bMinutes, tc.bSeconds); double nPos = tsDuration.TotalSeconds / pf.Width * e.X; TimeSpan tsPos = TimeSpan.FromSeconds(nPos); DvdHMSFTimeCode nTc = new DvdHMSFTimeCode(); nTc.bHours = (byte)tsPos.Hours; nTc.bMinutes = (byte)tsPos.Minutes; nTc.bSeconds = (byte)tsPos.Seconds; hr = dvdCtrl.PlayAtTime(nTc, DvdCmdFlags.SendEvents, out cmdOption); DsError.ThrowExceptionForHR(hr); if (cmdOption != null) { pendingCmd = true; } } } }
private void UpdateMainTitle() { if (this.InvokeRequired) this.Invoke(new BlankInvoke(UpdateMainTitle)); else { // If no file is loaded, just show the application title if (this.filename.Count == 0) this.Text = "EVR Media Player"; else { //string media = (isAudioOnly) ? "Audio" : "Video"; string muted = (currentVolume == VolumeSilence) ? " Mute" : ""; string paused = (currentState == PlayState.Paused) ? " Paused" : ""; if (dvdGraph == null) { string timeStatus = string.Empty; if (GetPositionAndDuration(out currentPosition, out fileDuration) >= 0) { pf.Value = (int)TimeSpan.FromTicks(currentPosition).TotalSeconds; pf.Maximum = (int)TimeSpan.FromTicks(fileDuration).TotalSeconds; DateTime cDate = new DateTime(currentPosition); DateTime fDuration = new DateTime(fileDuration); timeStatus = string.Format(" {0:HH:mm:ss}-{1:HH:mm:ss}", cDate, fDuration); } this.Text = String.Format("{0}{1}{2}{3}", System.IO.Path.GetFileName(this.filename[currentIndex]), muted, paused, timeStatus); } else { DvdHMSFTimeCode tc = new DvdHMSFTimeCode(); DvdTimeCodeFlags tf; int hr = dvdInfo.GetTotalTitleTime(tc, out tf); string ti = String.Format("{0:00}:{1:00}:{2:00}", currnTime.bHours, currnTime.bMinutes, currnTime.bSeconds); string tt = String.Format("{0:00}:{1:00}:{2:00}", tc.bHours, tc.bMinutes, tc.bSeconds); string pr = string.Format(" {0}x", dvdPlayRate); if (dvdPlayRate == 1) pr = string.Empty; this.Text = String.Format("Chapter:{0} Title:{1} {2}-{3}{4}", currnChapter, currnTitle, ti, tt, pr); TimeSpan tsDuration = new TimeSpan(tc.bHours, tc.bMinutes, tc.bSeconds); TimeSpan tsPos = new TimeSpan(currnTime.bHours, currnTime.bMinutes, currnTime.bSeconds); pf.Value = (int)tsPos.TotalSeconds; pf.Maximum = (int)tsDuration.TotalSeconds; } } } }