本文整理汇总了C#中IMediaControl类的典型用法代码示例。如果您正苦于以下问题:C# IMediaControl类的具体用法?C# IMediaControl怎么用?C# IMediaControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMediaControl类属于命名空间,在下文中一共展示了IMediaControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlayerCore
public PlayerCore(string file)
{
graphBuilder = (new FilterGraph()) as IFilterGraph2;
if (graphBuilder == null) return;
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = graphBuilder as IMediaSeeking;
audioControl = graphBuilder as IBasicAudio;
if (mediaControl == null || mediaSeeking == null || audioControl == null) return;
//int hr = mediaControl.RenderFile(file);
FileInfo info = new FileInfo(file);
ISupport support = Supports.Instance[info.Extension];
int hr = -1;
if (support != null)
hr = support.RenderGraph(graphBuilder, file);
else
hr = mediaControl.RenderFile(file);
fileName = file;
if (hr != 0) errorStack.Push(hr);
if (hr != 0) return;
mediaSeeking.SetTimeFormat(TimeFormat.MediaTime);
isValidate = true;
window = graphBuilder as IVideoWindow;
if (window != null)
{
int width = 0;
int height = 0;
window.get_Width(out width);
window.get_Height(out height);
nativeSize = new Size(width, height);
}
}
示例2: BuildGraph
private void BuildGraph(string fileName)
{
int hr = 0;
try
{
graphBuilder = (IFilterGraph2)new FilterGraph();
mediaControl = (IMediaControl)graphBuilder;
mediaSeeking = (IMediaSeeking)graphBuilder;
mediaPosition = (IMediaPosition)graphBuilder;
vmr9 = (IBaseFilter)new VideoMixingRenderer9();
ConfigureVMR9InWindowlessMode();
hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
DsError.ThrowExceptionForHR(hr);
hr = graphBuilder.RenderFile(fileName, null);
DsError.ThrowExceptionForHR(hr);
}
catch (Exception e)
{
CloseInterfaces();
MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例3: PlayCinematic
// Starts playing a new cinematic
public void PlayCinematic(string file, int x, int y, int w, int h)
{
// Lame bugfix: DirectShow and Fullscreen doesnt like eachother
if (CVars.Instance.Get("r_fs", "0", CVarFlags.ARCHIVE).Integer == 1)
{
if (AlterGameState)
{
playing = true;
StopCinematic();
}
return;
}
// Check if file exists
if (FileCache.Instance.Contains(file))
file = FileCache.Instance.GetFile(file).FullName;
else
{
if (AlterGameState)
{
playing = true;
StopCinematic();
}
Common.Instance.WriteLine("PlayCinematic: Could not find video: {0}", file);
return;
}
// Have the graph builder construct its the appropriate graph automatically
this.graphBuilder = (IGraphBuilder)new FilterGraph();
int hr = graphBuilder.RenderFile(file, null);
DsError.ThrowExceptionForHR(hr);
mediaControl = (IMediaControl)this.graphBuilder;
mediaEventEx = (IMediaEventEx)this.graphBuilder;
videoWindow = this.graphBuilder as IVideoWindow;
basicVideo = this.graphBuilder as IBasicVideo;
// Setup the video window
hr = this.videoWindow.put_Owner(Renderer.Instance.form.Handle);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
// Set the video size
//int lWidth, lHeight;
//hr = this.basicVideo.GetVideoSize(out lWidth, out lHeight);
hr = this.videoWindow.SetWindowPosition(x, y, w, h);
videoWindow.put_FullScreenMode((CVars.Instance.Get("r_fs", "0", CVarFlags.ARCHIVE).Integer == 1) ? OABool.True : OABool.False);
DsError.ThrowExceptionForHR(hr);
// Run the graph to play the media file
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
playing = true;
if (AlterGameState)
Client.Instance.state = CubeHags.common.ConnectState.CINEMATIC;
Common.Instance.WriteLine("Playing cinematic: {0}", file);
EventCode code;
}
示例4: SimplePlayer
/// <summary>
/// This constructor internally build a DirectShow graph using the given file name parameter.
/// </summary>
/// <param name="filename">A media file.</param>
/// <remarks>This constructor use the BlackListManager class to bane the use of the ffdshow Audio and Video decoders during the Intelligent Connect graph building.</remarks>
public SimplePlayer(string filename)
{
if (string.IsNullOrEmpty(filename))
throw new ArgumentNullException("filename");
if (!File.Exists(filename))
throw new FileNotFoundException();
this.graphBuilder = (IFilterGraph2)new FilterGraph();
#if DEBUG
this.rot = new DsROTEntry(this.graphBuilder);
#endif
this.blackListManager = new BlackListManager(this.graphBuilder);
// blacklist the ffdshow Audio Decoder filter
this.blackListManager.AddBlackListedFilter(new Guid("0F40E1E5-4F79-4988-B1A9-CC98794E6B55"));
// blacklist the ffdshow Video Decoder filter
this.blackListManager.AddBlackListedFilter(new Guid("04FE9017-F873-410E-871E-AB91661A4EF7"));
int hr = this.graphBuilder.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
this.mediaControl = (IMediaControl)this.graphBuilder;
this.mediaEvent = (IMediaEvent)this.graphBuilder;
}
示例5: CaptureForm
public CaptureForm()
{
InitializeComponent();
graph_builder = (IGraphBuilder)new FilterGraph();
media_control = (IMediaControl)graph_builder;
events = (IMediaEventEx)graph_builder;
grabber = (ISampleGrabber)new SampleGrabber();
AMMediaType media_type = new AMMediaType();
media_type.majorType = MediaType.Video;
media_type.subType = MediaSubType.RGB24;
grabber.SetMediaType( media_type );
grabber.SetCallback( this, 1 );
cbDevices.Items.AddRange( GetDevices( FilterCategory.VideoInputDevice ) );
}
示例6: ShowMedia
/// <summary>
/// Plays the given mediafile in the internal mediaplayer
/// </summary>
/// <param name="FilePath">File to play</param>
public void ShowMedia(string FilePath)
{
StopMedia();
Lbl_CurrentMedia.Text = Path.GetFileName(FilePath);
m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(FilePath);
m_objBasicAudio = m_objFilterGraph as IBasicAudio;
try
{
m_objVideoWindow = m_objFilterGraph as IVideoWindow;
m_objVideoWindow.Owner = (int)panel2.Handle;
//m_objVideoWindow.Owner = (int)panel1.Handle;
m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
m_objVideoWindow.SetWindowPosition(panel2.ClientRectangle.Left,
panel2.ClientRectangle.Top,
panel2.ClientRectangle.Width,
panel2.ClientRectangle.Height);
}
catch (Exception ex)
{
Console.WriteLine(ex);
m_objVideoWindow = null;
}
m_objMediaEvent = m_objFilterGraph as IMediaEvent;
m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);
m_objMediaPosition = m_objFilterGraph as IMediaPosition;
m_objMediaControl = m_objFilterGraph as IMediaControl;
m_objMediaControl.Run();
m_CurrentStatus = MediaStatus.Running;
UpdateMediaButtons();
//UpdateStatusBar();
//UpdateToolBar();
}
示例7: SetControls
public void SetControls()
{
if (selectedDevice == null)
{
launcher = null;
mediaPlayer = null;
mediaControl = null;
tvControl = null;
volumeControl = null;
toastControl = null;
textInputControl = null;
mouseControl = null;
externalInputControl = null;
powerControl = null;
keyControl = null;
playListControl = null;
webAppLauncher = null;
}
else
{
launcher = selectedDevice.GetCapability<ILauncher>();
mediaPlayer = selectedDevice.GetCapability<IMediaPlayer>();
mediaControl = selectedDevice.GetCapability<IMediaControl>();
tvControl = selectedDevice.GetCapability<ITvControl>();
volumeControl = selectedDevice.GetCapability<IVolumeControl>();
toastControl = selectedDevice.GetCapability<IToastControl>();
textInputControl = selectedDevice.GetCapability<ITextInputControl>();
mouseControl = selectedDevice.GetCapability<IMouseControl>();
externalInputControl = selectedDevice.GetCapability<IExternalInputControl>();
powerControl = selectedDevice.GetCapability<IPowerControl>();
keyControl = selectedDevice.GetCapability<IKeyControl>();
playListControl = selectedDevice.GetCapability<IPlayListControl>();
webAppLauncher = selectedDevice.GetCapability<IWebAppLauncher>();
}
SetControlsMedia();
SetWebAppControls();
SetControlControls();
SetControlApps();
SetControlKeys();
SetControlSystem();
}
示例8: cmdOpen_Click
private void cmdOpen_Click(object sender, EventArgs e)
{
// Allow the user to choose a file.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
if (DialogResult.OK == openFileDialog.ShowDialog())
{
// Stop the playback for the current movie, if it exists.
if (mc != null) mc.Stop();
mc = null;
videoWindow = null;
// Load the movie file.
FilgraphManager graphManager = new FilgraphManager();
graphManager.RenderFile(openFileDialog.FileName);
// Attach the view to a picture box on the form.
try
{
videoWindow = (IVideoWindow)graphManager;
videoWindow.Owner = (int)pictureBox1.Handle;
videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
videoWindow.SetWindowPosition(pictureBox1.ClientRectangle.Left,
pictureBox1.ClientRectangle.Top,
pictureBox1.ClientRectangle.Width,
pictureBox1.ClientRectangle.Height);
}
catch
{
// An error can occur if the file does not have a vide
// source (for example, an MP3 file.)
// You can ignore this error and still allow playback to
// continue (without any visualization).
}
// Start the playback (asynchronously).
mc = (IMediaControl)graphManager;
mc.Run();
}
}
示例9: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2) new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
try
{
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber) new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph( m_FilterGraph );
DsError.ThrowExceptionForHR( hr );
// Add the video device
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
DsError.ThrowExceptionForHR( hr );
IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
// If any of the default config items are set
if (iFrameRate + iHeight + iWidth > 0)
{
SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
}
hr = capGraph.RenderStream( PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt );
DsError.ThrowExceptionForHR( hr );
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (capGraph != null)
{
Marshal.ReleaseComObject(capGraph);
capGraph = null;
}
}
}
示例10: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, AMMediaType media)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2) new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
try
{
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber) new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph( m_FilterGraph );
DsError.ThrowExceptionForHR( hr );
// Add the video device
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
DsError.ThrowExceptionForHR( hr );
// add video crossbar
// thanks to Andrew Fernie - this is to get tv tuner cards working
IAMCrossbar crossbar = null;
object o;
hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMCrossbar).GUID, out o);
if (hr >= 0)
{
crossbar = (IAMCrossbar)o;
int oPin, iPin;
int ovLink, ivLink;
ovLink = ivLink = 0;
crossbar.get_PinCounts(out oPin, out iPin);
int pIdxRel;
PhysicalConnectorType tp;
for (int i = 0; i < iPin; i++)
{
crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out tp);
if (tp == PhysicalConnectorType.Video_Composite) ivLink = i;
}
for (int i = 0; i < oPin; i++)
{
crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out tp);
if (tp == PhysicalConnectorType.Video_VideoDecoder) ovLink = i;
}
try
{
crossbar.Route(ovLink, ivLink);
o = null;
}
catch
{
throw new Exception("Failed to get IAMCrossbar");
}
}
//add AVI Decompressor
IBaseFilter pAVIDecompressor = (IBaseFilter)new AVIDec();
hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
DsError.ThrowExceptionForHR(hr);
//
IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
DsError.ThrowExceptionForHR( hr );
SetConfigParms(capGraph, capFilter, media);
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt);
if (hr < 0)
{
hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt);
}
DsError.ThrowExceptionForHR( hr );
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
//.........这里部分代码省略.........
示例11: InitInterfaces
private void InitInterfaces()
{
try
{
// initialise the graph and get the graph builder and media control from it
_graph = new FilterGraph();
_mediaEvent = (IMediaEventEx)_graph;
_graphBuilder = (IGraphBuilder)_graph;
_mediaControl = (IMediaControl)_graph;
}
catch (Exception ex)
{
throw new ApplicationException("Couldn't initialise filter graph: " + ex.Message);
}
}
示例12: SetupGraph
// Build the capture graph for grabber and renderer.</summary>
// (Control to show video in, Filename to play)
private void SetupGraph(string FileName)
{
int hr;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
// Get a ICaptureGraphBuilder2 to help build the graph
ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
try
{
// Link the ICaptureGraphBuilder2 to the IFilterGraph2
hr = icgb2.SetFiltergraph(m_FilterGraph);
DsError.ThrowExceptionForHR(hr);
// Add the filters necessary to render the file. This function will
// work with a number of different file types.
IBaseFilter sourceFilter = null;
hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
DsError.ThrowExceptionForHR(hr);
// Get the SampleGrabber interface
m_sampGrabber = (ISampleGrabber)new SampleGrabber();
IBaseFilter baseGrabFlt = (IBaseFilter)m_sampGrabber;
// Configure the Sample Grabber
ConfigureSampleGrabber(m_sampGrabber);
// Add it to the filter
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
// Add the null renderer to the graph
IBaseFilter nullrenderer = new NullRenderer() as IBaseFilter;
hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// Connect the pieces together, use the default renderer
hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, nullrenderer);
DsError.ThrowExceptionForHR(hr);
// Now that the graph is built, read the dimensions of the bitmaps we'll be getting
SaveSizeInfo(m_sampGrabber);
// Grab some other interfaces
m_mediaEvent = m_FilterGraph as IMediaEvent;
m_mediaCtrl = m_FilterGraph as IMediaControl;
}
finally
{
if (icgb2 != null)
{
Marshal.ReleaseComObject(icgb2);
icgb2 = null;
}
}
#if DEBUG
// Double check to make sure we aren't releasing something
// important.
GC.Collect();
GC.WaitForPendingFinalizers();
#endif
}
示例13: InitGraph
private void InitGraph(string filename)
{
int hr = 0;
//IntPtr hEvent;
if (filename == string.Empty)
return;
this.filterGraph = new FilterGraph() as IFilterGraph2;
#if DEBUG
//rot = new DsROTEntry(this.filterGraph);
#endif
// Have the graph builder construct its the appropriate graph automatically
hr = this.filterGraph.RenderFile(filename, null);
DsError.ThrowExceptionForHR(hr);
// QueryInterface for DirectShow interfaces
this.mediaControl = this.filterGraph as IMediaControl;
this.mediaSeeking = this.filterGraph as IMediaSeeking;
//this.mediaEvent = this.graphBuilder as IMediaEvent;
// Query for audio interfaces, which may not be relevant for video-only files
this.basicAudio = this.filterGraph as IBasicAudio;
// Complete window initialization
this.currentPlaybackRate = 1.0;
}
示例14: CloseInterfaces
public void CloseInterfaces()
{
if (mediaEvent != null)
{
hresult = mediaControl.Stop();
Marshal.ThrowExceptionForHR(hresult);
}
mediaControl = null;
mediaEvent = null;
graphBuilder = null;
if (filterGraph != null) Marshal.ReleaseComObject(filterGraph);
filterGraph = null;
}
示例15: AudioAnimate
// Methods
internal AudioAnimate(string prefix, string localname, string ns, SvgDocument doc)
: base(prefix, localname, ns, doc)
{
this.m_objFilterGraph = null;
this.m_objBasicAudio = null;
this.m_objMediaEvent = null;
this.m_objMediaEventEx = null;
this.m_objMediaPosition = null;
this.m_objMediaControl = null;
this.fillColor = Color.Khaki;
this.fileName = string.Empty;
this.m_CurrentStatus = MediaStatus.None;
this.timer = new Timer();
this.oldtime = 0f;
this.timertime = 0f;
this.timer.Interval = 100;
this.timer.Tick += new EventHandler(this.TimerTick);
}