Runprogram - QuickTimePlayer
Runprogram - QuickTimePlayer
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...
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...
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Re: Runprogram - QuickTimePlayer
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.
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
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Re: Runprogram - QuickTimePlayer
This will open any file in associated program:
Or, if you want to use QuickTime specifically:
Code: Select all
RunProgram("open","/path/to/file","")
Code: Select all
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"/path/to/file\"","")
Re: Runprogram - QuickTimePlayer
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.
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
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Re: Runprogram - QuickTimePlayer
The Movie library is broken on macOS 10.15 and above so it's good you are using RunProgram
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Runprogram - QuickTimePlayer
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?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.
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
Just a thought...
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: Runprogram - QuickTimePlayer
You can't use variables inside strings (yet?).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
Code: Select all
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")
Re: Runprogram - QuickTimePlayer
Thanks again deseven,
What a sequence in the RunProgram command!
That did the trick. Now I can use Quicktime for mp4s
and VLC for .ts and .avi files
It is surprising how intuitive it is to just click on the listing in my program and have it play immediately.
What a sequence in the RunProgram command!
That did the trick. Now I can use Quicktime for mp4s
Code: Select all
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")
Code: Select all
RunProgram("open",~"-b org.videolan.vlc \"" + filepath$ + filename$ + ~"\"","")
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Re: Runprogram - QuickTimePlayer
You're welcome!
However, since VLC is not a default application, i suggest checking if it's installed first:
Or just use open without defining a specific app.
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
Re: Runprogram - QuickTimePlayer
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.
I'll add this and add it to my library of snippets.
I'm really pleased at how well this is working.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1