本文整理汇总了C#中IMediaSeeking.GetCurrentPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IMediaSeeking.GetCurrentPosition方法的具体用法?C# IMediaSeeking.GetCurrentPosition怎么用?C# IMediaSeeking.GetCurrentPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediaSeeking
的用法示例。
在下文中一共展示了IMediaSeeking.GetCurrentPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getCurPos
public static int getCurPos(IMediaSeeking mediaSeeking, double fps)
{
if (mediaSeeking == null) return 1;
long cur;
mediaSeeking.GetCurrentPosition(out cur);
if (!isInFrames(mediaSeeking))
cur = refTime2frame(cur,fps);
return (int)cur;
}
示例2: Transcode
//.........这里部分代码省略.........
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut0, pinIn0);
if (hr != 0)
{
Log.Error("TSReader2MP4: FAILED: unable to connect audio pins :0x{0:X}", hr);
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut1, pinIn1);
if (hr != 0)
{
Log.Error("TSReader2MP4: FAILED: unable to connect video pins :0x{0:X}", hr);
Cleanup();
return false;
}
//add encoders, muxer & filewriter
if (!AddCodecs(graphBuilder, info)) return false;
//setup graph controls
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = tsreaderSource as IMediaSeeking;
mediaEvt = graphBuilder as IMediaEventEx;
mediaPos = graphBuilder as IMediaPosition;
//get file duration
Log.Info("TSReader2MP4: Get duration of recording");
long lTime = 5 * 60 * 60;
lTime *= 10000000;
long pStop = 0;
hr = mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
AMSeekingSeekingFlags.NoPositioning);
if (hr == 0)
{
long lStreamPos;
mediaSeeking.GetCurrentPosition(out lStreamPos); // stream position
m_dDuration = lStreamPos;
lTime = 0;
mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
AMSeekingSeekingFlags.NoPositioning);
}
double duration = m_dDuration / 10000000d;
Log.Info("TSReader2MP4: recording duration: {0}", MediaPortal.Util.Utils.SecondsToHMSString((int)duration));
//run the graph to initialize the filters to be sure
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2MP4: FAILED: unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
int maxCount = 20;
while (true)
{
long lCurrent;
mediaSeeking.GetCurrentPosition(out lCurrent);
double dpos = (double)lCurrent;
dpos /= 10000000d;
System.Threading.Thread.Sleep(100);
if (dpos >= 2.0d) break;
maxCount--;
if (maxCount <= 0) break;
}
mediaControl.Stop();
FilterState state;
mediaControl.GetState(500, out state);
GC.Collect();
GC.Collect();
GC.Collect();
GC.WaitForPendingFinalizers();
graphBuilder.RemoveFilter(mp4Muxer);
graphBuilder.RemoveFilter(h264Encoder);
graphBuilder.RemoveFilter(aacEncoder);
graphBuilder.RemoveFilter((IBaseFilter)fileWriterFilter);
if (!AddCodecs(graphBuilder, info)) return false;
//Set Encoder quality & Muxer settings
if (!EncoderSet(graphBuilder, info)) return false;
//start transcoding - run the graph
Log.Info("TSReader2MP4: start transcoding");
//setup flow control
//need to leverage CBAsePin, CPullPin & IAsyncReader methods.
IAsyncReader synchVideo = null;
mediaSample = VideoCodec as IMediaSample;
hr = synchVideo.SyncReadAligned(mediaSample);
//So we only parse decoder output whent the encoders are ready.
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2MP4: FAILED:unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
}
catch (Exception ex)
{
Log.Error("TSReader2MP4: Unable create graph: {0}", ex.Message);
Cleanup();
return false;
}
return true;
}
示例3: Transcode
//.........这里部分代码省略.........
return false;
}
}
Log.Info("TSReader2WMV: connect tsreader->audio/video decoders");
//connect output #0 (audio) of tsreader->audio decoder input pin 0
//connect output #1 (video) of tsreader->video decoder input pin 0
pinIn0 = DsFindPin.ByDirection(AudioCodec, PinDirection.Input, 0); //audio
pinIn1 = DsFindPin.ByDirection(VideoCodec, PinDirection.Input, 0); //video
if (pinIn0 == null || pinIn1 == null)
{
Log.Error("TSReader2WMV: FAILED: unable to get pins of video/audio codecs");
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut0, pinIn0);
if (hr != 0)
{
Log.Error("TSReader2WMV: FAILED: unable to connect audio pins :0x{0:X}", hr);
Cleanup();
return false;
}
hr = graphBuilder.Connect(pinOut1, pinIn1);
if (hr != 0)
{
Log.Error("TSReader2WMV: FAILED: unable to connect video pins :0x{0:X}", hr);
Cleanup();
return false;
}
string outputFilename = System.IO.Path.ChangeExtension(info.file, ".wmv");
if (!AddWmAsfWriter(outputFilename, quality, standard)) return false;
Log.Info("TSReader2WMV: start pre-run");
mediaControl = graphBuilder as IMediaControl;
mediaSeeking = tsreaderSource as IMediaSeeking;
mediaEvt = graphBuilder as IMediaEventEx;
mediaPos = graphBuilder as IMediaPosition;
//get file duration
long lTime = 5 * 60 * 60;
lTime *= 10000000;
long pStop = 0;
hr = mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
AMSeekingSeekingFlags.NoPositioning);
if (hr == 0)
{
long lStreamPos;
mediaSeeking.GetCurrentPosition(out lStreamPos); // stream position
m_dDuration = lStreamPos;
lTime = 0;
mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
AMSeekingSeekingFlags.NoPositioning);
}
double duration = m_dDuration / 10000000d;
Log.Info("TSReader2WMV: movie duration:{0}", Util.Utils.SecondsToHMSString((int)duration));
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2WMV: FAILED: unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
int maxCount = 20;
while (true)
{
long lCurrent;
mediaSeeking.GetCurrentPosition(out lCurrent);
double dpos = (double)lCurrent;
dpos /= 10000000d;
System.Threading.Thread.Sleep(100);
if (dpos >= 2.0d) break;
maxCount--;
if (maxCount <= 0) break;
}
Log.Info("TSReader2WMV: pre-run done");
Log.Info("TSReader2WMV: Get duration of movie");
mediaControl.Stop();
FilterState state;
mediaControl.GetState(500, out state);
GC.Collect();
GC.Collect();
GC.Collect();
GC.WaitForPendingFinalizers();
Log.Info("TSReader2WMV: reconnect mpeg2 video codec->ASF WM Writer");
graphBuilder.RemoveFilter(fileWriterbase);
if (!AddWmAsfWriter(outputFilename, quality, standard)) return false;
Log.Info("TSReader2WMV: Start transcoding");
hr = mediaControl.Run();
if (hr != 0)
{
Log.Error("TSReader2WMV:FAILED:unable to start graph :0x{0:X}", hr);
Cleanup();
return false;
}
}
catch (Exception e)
{
// TODO: Handle exceptions.
Log.Error("unable to transcode file:{0} message:{1}", info.file, e.Message);
return false;
}
return true;
}
示例4: CheckGraphConversion
private bool CheckGraphConversion(ref IMediaSeeking mediaSeeking)
{
int hr;
IMediaEvent mediaEvent = (IMediaEvent)currentFilterGraph;
// Check the graph / conversion is going ok, and raise any progress events
EventCode statusCode;
hr = mediaEvent.WaitForCompletion(100, out statusCode);
switch (statusCode)
{
case EventCode.Complete:
return true;
case 0: // Still going - fire event with an update on where we are
if (mediaSeeking != null)
{
long curPos;
mediaSeeking.GetCurrentPosition(out curPos);
long length;
mediaSeeking.GetDuration(out length);
double progress = curPos * 100.0 / (double)length;
if (ConversionProgressChanged != null)
ConversionProgressChanged(new object(), new ProgressChangedEventArgs(progress));
}
return false;
default: // Error
EventCode tryCode;
IntPtr lp1, lp2;
hr = mediaEvent.GetEvent(out tryCode, out lp1, out lp2, 200);
DsError.ThrowExceptionForHR(hr);
throw new Exception(statusCode.ToString());
}
}