本文整理汇总了C#中IMediaPosition类的典型用法代码示例。如果您正苦于以下问题:C# IMediaPosition类的具体用法?C# IMediaPosition怎么用?C# IMediaPosition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMediaPosition类属于命名空间,在下文中一共展示了IMediaPosition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: Play
//TODO Fichier déjà utilisé.... surement par Quartz. Essayer de libérer les ressources de la librairie
public void Play(Guid id, byte[] file)
{
objFilterGraph = new FilgraphManager();
audio = (IBasicAudio) objFilterGraph;
//pb d'accès concurrenciel
string path = ConfigurationManager.AppSettings["MediaCache"] + id + ".mp3";
File.WriteAllBytes(path, file);
objFilterGraph.RenderFile(path);
objMediaPosition = objFilterGraph as IMediaPosition;
objFilterGraph.Run();
tmProgressionFlux = new Timer(1000) { Enabled = true };
tmProgressionFlux.Elapsed += TmProgressionFluxTick;
TimerResume();
}
示例3: 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();
}
示例4: Initialize
public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
{
const int wsChild = 0x40000000;
string ext = System.IO.Path.GetExtension(videoFileName).ToLower();
bool isAudio = ext == ".mp3" || ext == ".wav" || ext == ".wma" || ext == ".ogg" || ext == ".mpa" || ext == ".m4a" || ext == ".ape" || ext == ".aiff" || ext == ".flac" || ext == ".acc" || ext == ".mka";
OnVideoLoaded = onVideoLoaded;
OnVideoEnded = onVideoEnded;
VideoFileName = videoFileName;
_owner = ownerControl;
_quartzFilgraphManager = new FilgraphManager();
_quartzFilgraphManager.RenderFile(VideoFileName);
if (!isAudio)
{
_quartzVideo = _quartzFilgraphManager as IVideoWindow;
_quartzVideo.Owner = (int)ownerControl.Handle;
_quartzVideo.SetWindowPosition(0, 0, ownerControl.Width, ownerControl.Height);
_quartzVideo.WindowStyle = wsChild;
}
//Play();
if (!isAudio)
(_quartzFilgraphManager as IBasicVideo).GetVideoSize(out _sourceWidth, out _sourceHeight);
_owner.Resize += OwnerControlResize;
_mediaPosition = (IMediaPosition)_quartzFilgraphManager;
if (OnVideoLoaded != null)
{
_videoLoader = new BackgroundWorker();
_videoLoader.RunWorkerCompleted += VideoLoaderRunWorkerCompleted;
_videoLoader.DoWork += VideoLoaderDoWork;
_videoLoader.RunWorkerAsync();
}
OwnerControlResize(this, null);
_videoEndTimer = new Timer { Interval = 500 };
_videoEndTimer.Tick += VideoEndTimerTick;
_videoEndTimer.Start();
if (!isAudio)
_quartzVideo.MessageDrain = (int)ownerControl.Handle;
}
示例5: PlayMovieInWindow
//.........这里部分代码省略.........
if (EVRControl == null)
{
//Ищем рендерер и ВКЛЮЧАЕМ соблюдение аспекта (рендерер сам подгонит картинку под размер окна, с учетом аспекта)
IsRendererARFixed = false;
IBaseFilter filter = null;
graphBuilder.FindFilterByName("Video Renderer", out filter);
if (filter != null)
{
IVMRAspectRatioControl vmr = filter as IVMRAspectRatioControl;
if (vmr != null)
{
DsError.ThrowExceptionForHR(vmr.SetAspectRatioMode(VMRAspectRatioMode.LetterBox));
IsRendererARFixed = true;
}
}
else
{
graphBuilder.FindFilterByName("Video Mixing Renderer 9", out filter);
if (filter != null)
{
IVMRAspectRatioControl9 vmr9 = filter as IVMRAspectRatioControl9;
if (vmr9 != null)
{
DsError.ThrowExceptionForHR(vmr9.SetAspectRatioMode(VMRAspectRatioMode.LetterBox));
IsRendererARFixed = true;
}
}
}
}
else
IsRendererARFixed = true;
this.mediaControl = (IMediaControl)this.graphBuilder;
this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
this.mediaPosition = (IMediaPosition)this.graphBuilder;
this.videoWindow = (EVRControl == null) ? this.graphBuilder as IVideoWindow : null;
this.basicVideo = (EVRControl == null) ? this.graphBuilder as IBasicVideo : null;
this.basicAudio = this.graphBuilder as IBasicAudio;
this.basicAudio.put_Volume(VolumeSet);
this.CheckIsAudioOnly();
if (!this.isAudioOnly)
{
if (videoWindow != null)
{
hr = this.videoWindow.put_Owner(this.source.Handle);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_MessageDrain(this.source.Handle);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_WindowStyle(DirectShowLib.WindowStyle.Child | DirectShowLib.WindowStyle.ClipSiblings | DirectShowLib.WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
}
this.MoveVideoWindow();
}
else
{
if (VHost != null)
{
VHost.Dispose();
VHost = null;
VHandle = IntPtr.Zero;
VHostElement.Child = null;
VHostElement.Visibility = Visibility.Collapsed;
}
}
hr = this.mediaEventEx.SetNotifyWindow(this.source.Handle, WMGraphNotify, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
//Восстанавливаем старую позицию
if (mediaload == MediaLoad.Update && oldpos != TimeSpan.Zero)
{
if (NaturalDuration >= oldpos)
{
hr = mediaPosition.put_CurrentPosition(oldpos.TotalSeconds);
DsError.ThrowExceptionForHR(hr);
}
}
//Восстанавливаем старый PlayState
if (mediaload == MediaLoad.Update && (oldplaystate == PlayState.Paused || oldplaystate == PlayState.Stopped))
{
hr = this.mediaControl.Pause();
DsError.ThrowExceptionForHR(hr);
this.currentState = PlayState.Paused;
this.SetPlayIcon();
}
else
{
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
this.currentState = PlayState.Running;
this.SetPauseIcon();
}
AddFiltersToMenu();
}
示例6: GetInterfaces
//.........这里部分代码省略.........
graphBuilder.Render(pins[0]);
}
}
#endregion
// Connect DVB subtitle filter pins in the graph
if (_mpegDemux != null && enableDvbSubtitles == true)
{
IMpeg2Demultiplexer demuxer = _mpegDemux as IMpeg2Demultiplexer;
hr = demuxer.CreateOutputPin(GetTSMedia(), "Pcr", out _pinPcr);
if (hr == 0)
{
Log.Info("RTSPPlayer:_pinPcr OK");
IPin pDemuxerPcr = DsFindPin.ByName(_mpegDemux, "Pcr");
IPin pSubtitlePcr = DsFindPin.ByName(_subtitleFilter, "Pcr");
hr = graphBuilder.Connect(pDemuxerPcr, pSubtitlePcr);
}
else
{
Log.Info("RTSPPlayer:Failed to create _pinPcr in demuxer:{0:X}", hr);
}
hr = demuxer.CreateOutputPin(GetTSMedia(), "Subtitle", out _pinSubtitle);
if (hr == 0)
{
Log.Info("RTSPPlayer:_pinSubtitle OK");
IPin pDemuxerSubtitle = DsFindPin.ByName(_mpegDemux, "Subtitle");
IPin pSubtitle = DsFindPin.ByName(_subtitleFilter, "In");
hr = graphBuilder.Connect(pDemuxerSubtitle, pSubtitle);
}
else
{
Log.Info("RTSPPlayer:Failed to create _pinSubtitle in demuxer:{0:X}", hr);
}
hr = demuxer.CreateOutputPin(GetTSMedia(), "PMT", out _pinPMT);
if (hr == 0)
{
Log.Info("RTSPPlayer:_pinPMT OK");
IPin pDemuxerSubtitle = DsFindPin.ByName(_mpegDemux, "PMT");
IPin pSubtitle = DsFindPin.ByName(_subtitleFilter, "PMT");
hr = graphBuilder.Connect(pDemuxerSubtitle, pSubtitle);
}
else
{
Log.Info("RTSPPlayer:Failed to create _pinPMT in demuxer:{0:X}", hr);
}
}
if (IsRadio == false)
{
if (!VMR9Util.g_vmr9.IsVMR9Connected)
{
//VMR9 is not supported, switch to overlay
Log.Info("RTSPPlayer: vmr9 not connected");
_mediaCtrl = null;
Cleanup();
return false;
}
VMR9Util.g_vmr9.SetDeinterlaceMode();
}
_mediaCtrl = (IMediaControl)graphBuilder;
mediaEvt = (IMediaEventEx)graphBuilder;
_mediaSeeking = (IMediaSeeking)graphBuilder;
mediaPos = (IMediaPosition)graphBuilder;
basicAudio = graphBuilder as IBasicAudio;
//DirectShowUtil.SetARMode(graphBuilder,AspectRatioMode.Stretched);
DirectShowUtil.EnableDeInterlace(graphBuilder);
if (VMR9Util.g_vmr9 != null)
{
m_iVideoWidth = VMR9Util.g_vmr9.VideoWidth;
m_iVideoHeight = VMR9Util.g_vmr9.VideoHeight;
}
if (audioRendererFilter != null)
{
Log.Info("RTSPPlayer9:set reference clock");
IMediaFilter mp = graphBuilder as IMediaFilter;
IReferenceClock clock = audioRendererFilter as IReferenceClock;
hr = mp.SetSyncSource(null);
hr = mp.SetSyncSource(clock);
Log.Info("RTSPPlayer9:set reference clock:{0:X}", hr);
}
Log.Info("RTSPPlayer: graph build successfull");
return true;
}
catch (Exception ex)
{
Error.SetError("Unable to play movie", "Unable build graph for VMR9");
Log.Error("RTSPPlayer:exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
CloseInterfaces();
return false;
}
}
示例7: GetDVDInterfaces
//.........这里部分代码省略.........
catch (Exception ex)
{
string strEx = ex.Message;
}
Guid riid;
if (_dvdInfo == null)
{
riid = typeof(IDvdInfo2).GUID;
hr = _dvdGraph.GetDvdInterface(riid, out comobj);
if (hr < 0)
{
Marshal.ThrowExceptionForHR(hr);
}
_dvdInfo = (IDvdInfo2)comobj;
comobj = null;
}
if (_dvdCtrl == null)
{
riid = typeof(IDvdControl2).GUID;
hr = _dvdGraph.GetDvdInterface(riid, out comobj);
if (hr < 0)
{
Marshal.ThrowExceptionForHR(hr);
}
_dvdCtrl = (IDvdControl2)comobj;
comobj = null;
}
_mediaCtrl = (IMediaControl)_graphBuilder;
_mediaEvt = (IMediaEventEx)_graphBuilder;
_basicAudio = _graphBuilder as IBasicAudio;
_mediaPos = (IMediaPosition)_graphBuilder;
_mediaSeek = (IMediaSeeking)_graphBuilder;
_mediaStep = (IVideoFrameStep)_graphBuilder;
_basicVideo = _graphBuilder as IBasicVideo2;
_videoWin = _graphBuilder as IVideoWindow;
// disable Closed Captions!
IBaseFilter baseFilter;
_graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
if (baseFilter == null)
{
_graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
}
if (baseFilter != null)
{
_line21Decoder = (IAMLine21Decoder)baseFilter;
if (_line21Decoder != null)
{
AMLine21CCState state = AMLine21CCState.Off;
hr = _line21Decoder.SetServiceState(state);
if (hr == 0)
{
logger.Info("DVDPlayer:Closed Captions disabled");
}
else
{
logger.Info("DVDPlayer:failed 2 disable Closed Captions");
}
}
}
/*
// get video window
if (_videoWin==null)
{
riid = typeof( IVideoWindow ).GUID;
hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
if( hr < 0 )
Marshal.ThrowExceptionForHR( hr );
_videoWin = (IVideoWindow) comobj; comobj = null;
}
*/
// GetFrameStepInterface();
DirectShowUtil.SetARMode(_graphBuilder, arMode);
DirectShowUtil.EnableDeInterlace(_graphBuilder);
//m_ovMgr = new OVTOOLLib.OvMgrClass();
//m_ovMgr.SetGraph(_graphBuilder);
return true;
}
catch (Exception)
{
//MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
CloseDVDInterfaces();
return false;
}
finally
{
if (comobj != null)
{
DirectShowUtil.ReleaseComObject(comobj);
}
comobj = null;
}
}
示例8: Initialize
public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
{
const int wsChild = 0x40000000;
var extension = System.IO.Path.GetExtension(videoFileName);
if (extension == null)
{
return;
}
string ext = extension.ToLower();
bool isAudio = ext == ".mp3" || ext == ".wav" || ext == ".wma" || ext == ".m4a";
OnVideoLoaded = onVideoLoaded;
OnVideoEnded = onVideoEnded;
VideoFileName = videoFileName;
owner = ownerControl;
quartzFilgraphManager = new FilgraphManager();
quartzFilgraphManager.RenderFile(VideoFileName);
if (!isAudio)
{
quartzVideo = quartzFilgraphManager as IVideoWindow;
if (quartzVideo != null)
{
quartzVideo.Owner = (int)ownerControl.Handle;
quartzVideo.SetWindowPosition(0, 0, ownerControl.Width, ownerControl.Height);
quartzVideo.WindowStyle = wsChild;
}
}
//Play();
if (!isAudio)
{
var basicVideo = quartzFilgraphManager as IBasicVideo;
if (basicVideo != null)
{
basicVideo.GetVideoSize(out sourceWidth, out sourceHeight);
}
}
owner.Resize += OwnerControlResize;
mediaPosition = (IMediaPosition)quartzFilgraphManager;
if (OnVideoLoaded != null)
{
videoLoader = new BackgroundWorker();
videoLoader.RunWorkerCompleted += VideoLoaderRunWorkerCompleted;
videoLoader.DoWork += VideoLoaderDoWork;
videoLoader.RunWorkerAsync();
}
OwnerControlResize(this, null);
videoEndTimer = new Timer { Interval = 500 };
videoEndTimer.Tick += VideoEndTimerTick;
videoEndTimer.Start();
if (isAudio)
{
return;
}
if (quartzVideo != null)
{
quartzVideo.MessageDrain = (int)ownerControl.Handle;
}
}
示例9: InitInterfaces
/// <summary>
/// Initialises DirectShow interfaces
/// </summary>
private void InitInterfaces()
{
var comtype = Type.GetTypeFromCLSID(Clsid.FilterGraph);
if (comtype == null)
throw new NotSupportedException("DirectX (8.1 or higher) not installed?");
var fg = Activator.CreateInstance(comtype);
m_graphBuilder = (IGraphBuilder)fg;
m_mediaControl = (IMediaControl)fg;
m_mediaEvent = (IMediaEventEx)fg;
m_mediaSeeking = (IMediaSeeking)fg;
m_mediaPosition = (IMediaPosition)fg;
m_basicAudio = (IBasicAudio)fg;
fg = null;
}
示例10: InitInterfaces
/// <summary>
/// Initialises DirectShow interfaces
/// </summary>
private void InitInterfaces()
{
fg = new FilterGraph();
gb = (IGraphBuilder)fg;
mc = (IMediaControl)fg;
me = (IMediaEventEx)fg;
ms = (IMediaSeeking)fg;
mp = (IMediaPosition)fg;
}
示例11: 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);
}
示例12: CleanUp
//Метод CleanUp (Зачистка графов)
public void CleanUp()
{
if (mediaControl != null) mediaControl.Stop();
CurrentStatus = mStatus.Stop;
if (videoWindow != null)
{
videoWindow.put_Visible(0);
videoWindow.put_Owner(new IntPtr(0));
}
if (mediaControl != null) mediaControl = null;
if (mediaPosition != null) mediaPosition = null;
if (mediaEventEx != null) mediaEventEx = null;
if (mediaEvent != null) mediaEvent = null;
if (videoWindow != null) videoWindow = null;
if (basicAudio != null) basicAudio = null;
if (graphBuilder != null) graphBuilder = null;
}
示例13: CleanUp
/**
* To clean up the FilterGraph and other Objects
* */
public void CleanUp()
{
if (m_objMediaControl != null)
m_objMediaControl.Stop();
if (m_objMediaEventEx != null)
m_objMediaEventEx.SetNotifyWindow(0, 0, 0);
if (m_objVideoWindow != null)
{
m_objVideoWindow.Visible = 0;
m_objVideoWindow.Owner = 0;
}
if (m_objMediaControl != null) m_objMediaControl = null;
if (m_objMediaPosition != null) m_objMediaPosition = null;
if (m_objMediaEventEx != null) m_objMediaEventEx = null;
if (m_objMediaEvent != null) m_objMediaEvent = null;
if (m_objVideoWindow != null) m_objVideoWindow = null;
if (m_objBasicAudio != null) m_objBasicAudio = null;
if (m_objFilterGraph != null) m_objFilterGraph = null;
}
示例14: CloseInterfaces
private void CloseInterfaces()
{
int hr = 0;
try
{
lock(this)
{
// Relinquish ownership (IMPORTANT!) after hiding video window
if (!this.isAudioOnly)
{
hr = this.videoWindow.put_Visible(OABool.False);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_Owner(IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
}
if (this.mediaEventEx != null)
{
hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
DsError.ThrowExceptionForHR(hr);
}
#if DEBUG
if (rot != null)
{
rot.Dispose();
rot = null;
}
#endif
// Release and zero DirectShow interfaces
if (this.mediaEventEx != null)
this.mediaEventEx = null;
if (this.mediaSeeking != null)
this.mediaSeeking = null;
if (this.mediaPosition != null)
this.mediaPosition = null;
if (this.mediaControl != null)
this.mediaControl = null;
if (this.basicAudio != null)
this.basicAudio = null;
if (this.basicVideo != null)
this.basicVideo = null;
if (this.videoWindow != null)
this.videoWindow = null;
if (this.frameStep != null)
this.frameStep = null;
if (this.graphBuilder != null)
Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
GC.Collect();
}
}
catch
{
}
}
示例15: CloseInterfaces
/// <summary>
/// Closes DirectShow interfaces
/// </summary>
private void CloseInterfaces()
{
if (me != null)
{
DsError.ThrowExceptionForHR(mc.Stop());
//0x00008001 = WM_GRAPHNOTIFY
DsError.ThrowExceptionForHR(me.SetNotifyWindow(IntPtr.Zero, 0x00008001, IntPtr.Zero));
}
mc = null;
me = null;
gb = null;
ms = null;
mp = null;
if (fg != null)
Marshal.ReleaseComObject(fg);
fg = null;
}