如何获取媒体长度(播放时间............. 急...........)(40分)

  • 主题发起人 主题发起人 dafu2
  • 开始时间 开始时间
D

dafu2

Unregistered / Unconfirmed
GUEST, unregistred user!
我是用DirectShow做播放器,在获取媒体长度时,老是报错!
搞不懂,晕........................
function TVideoPlayer.GetVideoPlayTime(const FileName: PWideChar): int64;
var
VideoLongth: int64;
Graph: IGraphBuilder;
MediaSeeking: IMediaSeeking;
begin

try
// CoInitialize(nil);
CoCreateInstance(CLSID_FilterGraph, nil, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, Graph);
Graph.RenderFile(FileName, nil);
Graph.QueryInterface(IID_IMediaSeeking, MediaSeeking);
//获取媒体总时间
MediaSeeking.SetTimeFormat(TIME_FORMAT_MEDIA_TIME);
MediaSeeking.GetDuration(VideoLongth);
Result := VideoLongth;
finally
Graph := nil;
MediaSeeking := nil;
//CoUninitialize;
end;

//Result := 100000000;
end;
 
看看这对你有没有帮助!
function GetAviLength(Alength: integer):string;
var
alltime: LongInt;
minutes, seconds: integer;
begin

MediaPlayer1.TimeFormat := tfmilliseconds;
alltime := Alength;
minutes := alltime div 60000;
seconds := (alltime - 60000 * minutes) div 1000;
Result:=inttostr(minutes) + '分' + inttostr(seconds) + '秒';
end;


长度:=GetAviLength(MEDIAPLAYER1.LENGTH);
 
问题自己解决,还是要谢谢 “清新空气”!
给分了哦!
 
后退
顶部