/// <summary> /// Restores the DVD playback state from a formerly saved resume state. /// </summary> /// <param name="resumeData">The resume data which was retrieved by calling <see cref="GetResumeState"/>.</param> private void SetResumeState(byte[] resumeData) { if ((resumeData != null) && (resumeData.Length > 0)) { IDvdState dvdState; int hr = _dvdInfo.GetState(out dvdState); if (hr < 0) { return; } IPersistMemory dvdStatePersistMemory = (IPersistMemory)dvdState; IntPtr stateData = Marshal.AllocHGlobal(resumeData.Length); Marshal.Copy(resumeData, 0, stateData, resumeData.Length); try { dvdStatePersistMemory.Load(stateData, (uint)resumeData.Length); } finally { Marshal.FreeHGlobal(stateData); } hr = _dvdCtrl.SetState(dvdState, DvdCmdFlags.Block, out _cmdOption); if (hr == 0) { return; } Marshal.ReleaseComObject(dvdState); } return; }
/// <summary> /// Gets the current DVD playback state as byte array. The resume state can be set later by calling /// <see cref="SetResumeState"/> with the returned byte array. /// </summary> /// <param name="resumeData">The resume data.</param> /// <returns><c>true</c>, if the resume state could successfully retrieved. In that case <paramref name="resumeData"/> /// contains the resume data. <c>false</c>, if the resume state could not be retrieved. In that case, /// <paramref name="resumeData"/> is <c>null</c>.</returns> private bool GetResumeState(out byte[] resumeData) { byte[] result = null; try { IDvdState dvdState; int hr = _dvdInfo.GetState(out dvdState); if (hr != 0) { return(false); } IPersistMemory dvdStatePersistMemory = (IPersistMemory)dvdState; if (dvdStatePersistMemory == null) { Marshal.ReleaseComObject(dvdState); return(false); } uint resumeSize; dvdStatePersistMemory.GetSizeMax(out resumeSize); if (resumeSize <= 0) { Marshal.ReleaseComObject(dvdStatePersistMemory); Marshal.ReleaseComObject(dvdState); return(false); } IntPtr stateData = Marshal.AllocCoTaskMem((int)resumeSize); try { dvdStatePersistMemory.Save(stateData, true, resumeSize); result = new byte[resumeSize]; Marshal.Copy(stateData, result, 0, (int)resumeSize); } catch { return(false); } Marshal.FreeCoTaskMem(stateData); Marshal.ReleaseComObject(dvdStatePersistMemory); Marshal.ReleaseComObject(dvdState); } catch { return(false); } finally { resumeData = result; } return(true); }