Page 1 of 1

Runprogram - QuickTimePlayer

Posted: Tue Nov 10, 2020 10:43 pm
by WilliamL
I have a program that lists video files and I'd like to have a button to use to open QuickTime Player and run the video file I'm on.

I think I need to use RunProgram() but I'm at a loss of how to do this. I've read the forum and tried a few things without success.

Any ideas would be appreciated.

[later]
Well, maybe it's easier to just use PlayMovie(0,WindowID(0)) in another window...

Re: Runprogram - QuickTimePlayer

Posted: Wed Nov 11, 2020 10:13 pm
by WilliamL
This is a very simple way to show the video file in my program with preservation of aspect ratio.

The only problem I've found is when I do a 2-finger swipe the player stops and I can't get it going again. Oh, and MovieLength() doesn't seem to be accurate and it only plays .mp4 & .m4v movies.

Code: Select all

EnableExplicit
Define event
Define moviefile$
#movieid=1
#moviewnd=2
Define aspectratio.f

If OpenWindow(#moviewnd, 0, 0,200,200, "Play movie", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
    Define reduceratio.f
    If InitMovie()
        moviefile$ = OpenFileRequester("Choose a mp4 file", "", "MP4 Files (*.mp4)", 0) 
        If Len(moviefile$)=0:End:EndIf
        LoadMovie(#movieid,moviefile$) 
        SetWindowTitle(#moviewnd,GetFilePart(moviefile$)+" ("+FormatDate("%hh:%ii:%ss",MovieLength(#movieid))+")")
        ;SetWindowTitle(#moviewnd,GetFilePart(moviefile$)+" ("+Str(MovieLength(#movieid))+")")
        PlayMovie(#movieid,WindowID(#moviewnd))
        ResizeWindow (#moviewnd,WindowX(#moviewnd),WindowY(#moviewnd),MovieWidth(#movieid),MovieHeight(#movieid))
        aspectratio=MovieWidth(#movieid)/MovieHeight(#movieid)
        If MovieWidth(#movieid)<800
            ResizeWindow (#moviewnd,WindowX(#moviewnd),WindowY(#moviewnd),MovieWidth(#movieid),MovieHeight(#movieid))
        Else
            reduceratio=800/MovieWidth(#movieid)
            ResizeWindow(#moviewnd,60,60,MovieWidth(#movieid)*reduceratio,MovieHeight(#movieid)*reduceratio)
            ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
        EndIf
    Else
        MessageRequester("Error", "Couldn't initialize movie!") 
    EndIf
EndIf

Repeat
    Event = WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
        FreeMovie(#movieid)
        End
    Case #PB_Event_SizeWindow
        ;ResizeWindow(#moviewnd,#PB_Ignore,#PB_Ignore,WindowWidth(#moviewnd),WindowHeight(#moviewnd))
        ;ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowHeight(#moviewnd))
        ResizeWindow(#moviewnd,#PB_Ignore,#PB_Ignore,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
        ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
    EndSelect
ForEver

Re: Runprogram - QuickTimePlayer

Posted: Thu Nov 12, 2020 10:20 pm
by deseven
This will open any file in associated program:

Code: Select all

RunProgram("open","/path/to/file","")
Or, if you want to use QuickTime specifically:

Code: Select all

RunProgram("open",~"-b com.apple.QuickTimePlayerX \"/path/to/file\"","")

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 1:30 am
by WilliamL
Thanks deseven,

I never would have figured this out!

The code to load QuickTime+file works fine if I write out the path+file.
Now how do I get the string variables of FilePath$+FileName$ into this command?
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"filepath$+filename$\","") ; doesn't work

The code to just 'open' doesn't work as I wrote it.

Code: Select all

;filepath$="MacBkPro_SSD/Users/vering2/Apps_stuff/Basic Apps/DVR+ directories/"
filepath$="/Users/vering2/Apps_stuff/Basic Apps/DVR+ directories/"
filename$="BugsBunny-OperaHare.mp4"

;RunProgram("open",~"-b com.apple.QuickTimePlayerX \"/path/to/file\"","");
;RunProgram("open",~"-b com.apple.QuickTimePlayerX \"/Users/vering2/Apps_stuff/Basic Apps/DVR+ directories/BugsBunny-OperaHare.mp4\"","") ; works fine
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"filepath$+filename$\","") ; doesn't work

;RunProgram("open","/path/to/file","")
;RunProgram("open","/Users/vering2/Apps_stuff/Basic Apps/DVR+ directories/BugsBunny-OperaHare.mp4","") ; doesn't work

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 7:21 am
by wilbert
The Movie library is broken on macOS 10.15 and above so it's good you are using RunProgram :)

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 8:14 am
by fsw
WilliamL wrote: I have a program that lists video files and I'd like to have a button to use to open QuickTime Player and run the video file I'm on.
If you wrote a program to list video files why not expanding it and use the AVPlayer API and add your own Player window to your app?

Here Wilberts example:
viewtopic.php?f=19&t=59977&hilit=aVPlayerItem&start=5

Player_SetFile(Player, Filename.s) is the procedure you would need for your app.

Works even on macOS Big Sur :D

Just a thought...

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 5:30 pm
by deseven
WilliamL wrote: The code to just 'open' doesn't work as I wrote it.

Code: Select all

RunProgram("open",~"-b com.apple.QuickTimePlayerX \"filepath$+filename$\","") ; doesn't work
You can't use variables inside strings (yet?).

Code: Select all

RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 6:03 pm
by WilliamL
Thanks again deseven,

What a sequence in the RunProgram command! :shock:

That did the trick. Now I can use Quicktime for mp4s

Code: Select all

RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")
and VLC for .ts and .avi files

Code: Select all

RunProgram("open",~"-b org.videolan.vlc \"" + filepath$ + filename$ + ~"\"","")
It is surprising how intuitive it is to just click on the listing in my program and have it play immediately.

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 6:28 pm
by deseven
You're welcome!

However, since VLC is not a default application, i suggest checking if it's installed first:

Code: Select all

If CocoaMessage(0,CocoaMessage(0,0,"NSWorkspace sharedWorkspace"),"absolutePathForAppBundleWithIdentifier:$",@"org.videolan.vlc")
  RunProgram("open",~"-b org.videolan.vlc \"" + filepath$ + filename$ + ~"\"","")
Else
  RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")
EndIf
Or just use open without defining a specific app.

Re: Runprogram - QuickTimePlayer

Posted: Fri Nov 13, 2020 6:37 pm
by WilliamL
Good point deseven!

I'll add this and add it to my library of snippets.

I'm really pleased at how well this is working. :)