home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Text;
- using System.Runtime.InteropServices;
- using MediaPlayer;
-
- namespace Homenet
- {
- public delegate bool StatusUpdateCallback(String title);
-
- public class VCR : MarshalByRefObject
- {
- public VCR()
- {
- Console.WriteLine("VCR Constructor");
- }
-
- MediaRequest _mediaRequest = null;
-
- public bool PlaySimple()
- {
- Console.WriteLine("Play");
-
- /*
- if (null == mediaPlayer)
- {
- StartMediaPlayer();
- }
-
- if (null != mediaPlayer)
- {
- mediaPlayer.Play();
- return true;
- }
- */
-
- return false;
- }
-
- public bool Play(String title)
- {
- Console.WriteLine("Play: {0}", title);
- mediaPlayer = null;
-
- /*
- if (null == mediaPlayer)
- {
- StartMediaPlayer();
- }
-
- if (null != mediaPlayer)
- {
- mediaPlayer.FileName = title;
- mediaPlayer.AutoRewind = true;
- mediaPlayer.AutoStart = false;
- mediaPlayer.Play();
-
- Console.WriteLine("VCR Playing " + title);
- }
- */
-
- Console.WriteLine("VCR Playing " + title);
-
- return true;
- }
-
- public bool PlayWithStatus(String title, BaseRemoteControl mediaStatus)
- {
- Play(title);
- mediaStatus.StatusUpdate("Playing: " + title);
- return true;
- }
-
- public bool PlayWithStatus(String title, IMediaStatus mediaStatus)
- {
- Play(title);
- mediaStatus.StatusUpdate("Playing: " + title);
- return true;
- }
-
- public bool PlayWithStatus(MediaRequest mediaRequest)
- {
- _mediaRequest = mediaRequest;
- Console.WriteLine("PlayWithStatus: MBV with embedded MBR");
-
- if ((null != mediaRequest) && (null != mediaRequest._mediaStatus))
- return PlayWithStatus(mediaRequest._title, mediaRequest._mediaStatus);
- else
-
- return true;
- }
-
- public bool PlayWithStatus(String title, StatusUpdateCallback callback)
- {
- Play(title);
-
- Console.WriteLine("PlayWithStatus: Delegate with MBR");
-
- if (null != callback)
- return callback(title);
- else
- return true;
- }
-
- public bool Pause()
- {
- Console.WriteLine("Pause");
- if (null != mediaPlayer)
- {
- mediaPlayer.Pause();
- }
- return true;
- }
-
- public bool Stop()
- {
- Console.WriteLine("Stop");
- if (null != mediaPlayer)
- {
- mediaPlayer.Stop();
- mediaPlayer.CurrentPosition = 0;
- }
- return true;
- }
-
- public bool Record()
- {
- //@@TODO
- return true;
- }
-
- // MediaPlayer
- private static Guid MediaPlayerCLSID = new Guid("22D6F312-B0F6-11D0-94AB-0080C74C7E95");
- private static Guid IID_MediaPlayer2 = new Guid("20D4F5E0-5475-11D2-9774-0000F80855E6");
- private static IMediaPlayer2 mediaPlayer = null;
-
- private void StartMediaPlayer()
- {
- IMediaPlayer2[] mediaPlayerArray = new IMediaPlayer2[1];
-
- CoCreateInstance(
- ref MediaPlayerCLSID,
- null,
- CLSCTX_LOCAL_SERVER,
- ref IID_MediaPlayer2,
- mediaPlayerArray);
-
- if (mediaPlayerArray[0] != null)
- {
- mediaPlayer = mediaPlayerArray[0];
- }
- }
-
-
- private const int CLSCTX_LOCAL_SERVER = 4;
-
- [sysimport(dll="Ole32"), returnshresult(true)]
- private static extern void CoCreateInstance(
- [in]
- ref Guid clsid,
- [nativetype(UnmanagedType.Interface)]
- object punkOuter,
- [nativetype(UnmanagedType.I4)]
- int context,
- [in]
- ref Guid iid,
- [in, @out, nativetype(UnmanagedType.LPArray)]
- IMediaPlayer2[] unknown);
-
- [sysimport(dll = "shell32.dll", charset = CharSet.Auto)]
- private static extern int ShellExecute(int hwnd, String lpVerb, String lpFile, String lpParameters, String lpDirectory, int nShowCmd);
- }
-
- public interface IMediaStatus
- {
- bool StatusUpdate(String status);
- }
-
- public class BaseRemoteControl : MarshalByRefObject
- {
- public virtual bool StatusUpdate(String title)
- {
- return true;
- }
- }
-
- [serializable]
- public class MediaRequest
- {
- // public MediaRequest(String title, IMediaStatus mediaStatus)
- public MediaRequest(String title, BaseRemoteControl mediaStatus)
- {
- _title = title;
- _mediaStatus = mediaStatus;
- }
-
- public String _title;
- //public IMediaStatus _mediaStatus;
- public BaseRemoteControl _mediaStatus;
- }
-
- }
-
-