My old software for obtaining the duration of a video (below) was written in Visual Basic and is in need of replacing…
While I had Real Basic back in 2009, I have just started developing in XOJO 2015, having seen Mediaplayer in the docs…
However, on further inspection, it appears that I need to play the video in a window in order to obtain the details.
My question is, does anyone know how to avoid this? It was not necessary in VB!
My VB code is below, if anyone can help me it would be greatly appreciated.
Thanks,
Richard Gamester
'
' Get Video Details
'
'Get an object on the filter graph manager
Set MediaControl = New FilgraphManager
' Get the various controls
Set MediaPosition = MediaControl
Set BasicVideo2 = MediaControl
'
On Error Resume Next
MediaControl.RenderFile Fl.Path
rc& = Err.Number
Msg$ = Err.Description
On Error GoTo 0
'
If rc& = 0 Then
'
Do ' Wait for RenderFile to complete
On Error Resume Next
Err.Clear
MediaControl.GetState 200, rc&
rc& = Err.Number
On Error GoTo 0
Loop While rc& <> 0
'
If UCase(Typ$) = "MP3" Then
' No video content...
Wide% = 0
High% = 0
Else
'
' A video may render, but have problems so not be
' playable until edited. This causes the get width to fail,
' so we check this first...
'
On Error Resume Next
Wide% = BasicVideo2.SourceWidth ' Video width 720 or 704
High% = BasicVideo2.SourceHeight
If Typ$ <> "JPG" Then
Frames = BasicVideo2.AvgTimePerFrame
If Frames > 0 Then Frames = 1 / Frames
Frames = Round(Frames, 1)
End If
rc& = Err.Number
Msg$ = Err.Description
On Error GoTo 0
End If
End If
'
I use mdls in OSX to get the movie duration (mpeg, mp4)
dim f as FolderItem = GetFolderItem ("xxxxxx", FolderItem.PathTypeNative)
If f <> Nil And f.Exists Then
dim sh as new shell
sh.execute "mdls -name kMDItemDurationSeconds '" + f.NativePath + "' | cut -d ""="" -f 2"
dim length as double = val(sh.Result)
MsgBox str(floor(length)) // length in Seconds
End If
Ok, I now have a Movie Player that works, and can get the duration - Thank You!
Out of interest, does anyone know how to get the width & height of the movie?
I’ve tried Player.Movie.MoveiWidth and Player.Movie.BaseWidth and I have even installed Quicktime
as mentioned in the documentation, but I still get zeros.
I also tried AutoResize, but that appears to have no affect.
Yes, I did look at ffprobe using the command line prompt and it works well.
But I could not work out how to save the console output and there is no save option.
I assume I have to build the command line and call Shell, with the console saved somehow.
I then just wait for completion (no problem with that) and then parse the result.
Unfortunately the consol bit is beyond me at present…
[quote=224140:@Richard Gamester]Yes, I did look at ffprobe using the command line prompt and it works well.
But I could not work out how to save the console output and there is no save option.
I assume I have to build the command line and call Shell, with the console saved somehow.
I then just wait for completion (no problem with that) and then parse the result.
Unfortunately the consol bit is beyond me at present…[/quote]
Use a synchronous shell with the same kind of command line, except you need to point the whole path to ffprobe. Then you get the result in the Shell.Result string property.
I have used ShellExecute in another project that controls TV recording software, but never looked at Shell.
Ah well you learn something new every day, even when you’re 70!