home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / HomeMedia / Homenet.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.7 KB  |  203 lines

  1. using System;
  2. using System.Text;
  3. using System.Runtime.InteropServices;
  4. using MediaPlayer;
  5.  
  6. namespace Homenet
  7. {
  8.     public delegate bool StatusUpdateCallback(String title);
  9.  
  10.     public class VCR : MarshalByRefObject
  11.     {
  12.         public VCR()
  13.         {
  14.             Console.WriteLine("VCR Constructor");
  15.         }
  16.  
  17.         MediaRequest _mediaRequest = null;
  18.  
  19.         public bool PlaySimple() 
  20.         {
  21.             Console.WriteLine("Play");
  22.  
  23. /*
  24.             if (null == mediaPlayer)
  25.             {
  26.                 StartMediaPlayer();
  27.             }
  28.  
  29.             if (null != mediaPlayer)
  30.             {
  31.                 mediaPlayer.Play();
  32.                 return true;
  33.             }
  34. */
  35.  
  36.             return false;
  37.         }
  38.  
  39.         public bool Play(String title) 
  40.         { 
  41.             Console.WriteLine("Play: {0}", title);
  42.             mediaPlayer = null;
  43.  
  44. /*
  45.             if (null == mediaPlayer)
  46.             {
  47.                 StartMediaPlayer();
  48.             }
  49.  
  50.             if (null != mediaPlayer)
  51.             {
  52.                 mediaPlayer.FileName = title;
  53.                 mediaPlayer.AutoRewind = true;
  54.                 mediaPlayer.AutoStart = false;
  55.                 mediaPlayer.Play();
  56.  
  57.                 Console.WriteLine("VCR Playing " + title);
  58.             }
  59. */
  60.  
  61.             Console.WriteLine("VCR Playing " + title);
  62.  
  63.             return true;
  64.         }
  65.  
  66.         public bool PlayWithStatus(String title, BaseRemoteControl mediaStatus)
  67.         {
  68.             Play(title);
  69.             mediaStatus.StatusUpdate("Playing: " + title);
  70.             return true;
  71.         }
  72.  
  73.         public bool PlayWithStatus(String title, IMediaStatus mediaStatus)
  74.         {
  75.             Play(title);
  76.             mediaStatus.StatusUpdate("Playing: " + title);
  77.             return true;
  78.         }
  79.  
  80.         public bool PlayWithStatus(MediaRequest mediaRequest)
  81.         {
  82.             _mediaRequest = mediaRequest;
  83.             Console.WriteLine("PlayWithStatus: MBV with embedded MBR");
  84.  
  85.             if ((null != mediaRequest) && (null != mediaRequest._mediaStatus))
  86.                 return PlayWithStatus(mediaRequest._title, mediaRequest._mediaStatus);
  87.             else
  88.  
  89.                 return true;
  90.         }
  91.  
  92.         public bool PlayWithStatus(String title, StatusUpdateCallback callback)
  93.         {
  94.             Play(title);
  95.  
  96.             Console.WriteLine("PlayWithStatus: Delegate with MBR");
  97.  
  98.             if (null != callback)
  99.                 return callback(title);
  100.             else
  101.                 return true;
  102.         }
  103.  
  104.         public bool Pause() 
  105.         { 
  106.             Console.WriteLine("Pause");
  107.             if (null != mediaPlayer)
  108.             {
  109.                 mediaPlayer.Pause();
  110.             }
  111.             return true;
  112.         }
  113.  
  114.         public bool Stop() 
  115.         { 
  116.             Console.WriteLine("Stop");
  117.             if (null != mediaPlayer)
  118.             {
  119.                 mediaPlayer.Stop();
  120.                 mediaPlayer.CurrentPosition = 0;
  121.             }
  122.             return true;
  123.         }
  124.  
  125.         public bool Record() 
  126.         { 
  127.             //@@TODO
  128.             return true;
  129.         }
  130.  
  131.         // MediaPlayer
  132.         private static Guid MediaPlayerCLSID = new Guid("22D6F312-B0F6-11D0-94AB-0080C74C7E95");
  133.         private static Guid IID_MediaPlayer2 = new Guid("20D4F5E0-5475-11D2-9774-0000F80855E6");
  134.         private static IMediaPlayer2 mediaPlayer = null;
  135.  
  136.         private void StartMediaPlayer()
  137.         {
  138.             IMediaPlayer2[] mediaPlayerArray = new IMediaPlayer2[1];
  139.  
  140.             CoCreateInstance(
  141.                             ref MediaPlayerCLSID, 
  142.                             null, 
  143.                             CLSCTX_LOCAL_SERVER, 
  144.                             ref IID_MediaPlayer2, 
  145.                             mediaPlayerArray);
  146.  
  147.             if (mediaPlayerArray[0] != null)
  148.             {
  149.                 mediaPlayer = mediaPlayerArray[0];
  150.             }
  151.         }
  152.  
  153.  
  154.         private const int CLSCTX_LOCAL_SERVER     = 4;
  155.  
  156.         [sysimport(dll="Ole32"), returnshresult(true)]
  157.         private static extern void CoCreateInstance(
  158.                                                    [in]
  159.                                                    ref Guid clsid,
  160.                                                    [nativetype(UnmanagedType.Interface)]
  161.                                                    object punkOuter,
  162.                                                    [nativetype(UnmanagedType.I4)]
  163.                                                    int context,
  164.                                                    [in]
  165.                                                    ref Guid iid,
  166.                                                    [in, @out, nativetype(UnmanagedType.LPArray)]
  167.                                                    IMediaPlayer2[] unknown);
  168.  
  169.         [sysimport(dll = "shell32.dll", charset = CharSet.Auto)]
  170.         private static extern int ShellExecute(int hwnd, String lpVerb, String lpFile, String lpParameters, String lpDirectory, int nShowCmd);
  171.     }
  172.  
  173.     public interface IMediaStatus
  174.     {
  175.         bool StatusUpdate(String status);
  176.     }
  177.  
  178.     public class BaseRemoteControl : MarshalByRefObject
  179.     {
  180.         public virtual bool StatusUpdate(String title)
  181.         {
  182.             return true;
  183.         }
  184.     }
  185.  
  186.     [serializable]
  187.     public class MediaRequest
  188.     {
  189. //    public MediaRequest(String title, IMediaStatus mediaStatus)
  190.         public MediaRequest(String title, BaseRemoteControl mediaStatus)
  191.         {
  192.             _title = title;
  193.             _mediaStatus = mediaStatus;
  194.         }
  195.  
  196.         public String _title;
  197.         //public IMediaStatus _mediaStatus;
  198.         public BaseRemoteControl _mediaStatus;
  199.     }
  200.  
  201. }
  202.  
  203.