It is currently Thu Jan 21, 2021 4:58 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Runprogram - QuickTimePlayer
PostPosted: Tue Nov 10, 2020 10:43 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1142
Location: Seattle, USA
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...

_________________
MacBook Pro-r, OSX 10.14.6 , PB 5.73LTS


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Wed Nov 11, 2020 10:13 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1142
Location: Seattle, USA
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:
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-r, OSX 10.14.6 , PB 5.73LTS


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Thu Nov 12, 2020 10:20 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jan 12, 2011 3:48 pm
Posts: 229
Location: Serbia
This will open any file in associated program:
Code:
RunProgram("open","/path/to/file","")


Or, if you want to use QuickTime specifically:
Code:
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"/path/to/file\"","")

_________________
PB examples collection
pb-osx-globalhotkeys
pb-osx-notifications


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 1:30 am 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1142
Location: Seattle, USA
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:
;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-r, OSX 10.14.6 , PB 5.73LTS


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 7:21 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
The Movie library is broken on macOS 10.15 and above so it's good you are using RunProgram :)

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 8:14 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
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...

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 5:30 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jan 12, 2011 3:48 pm
Posts: 229
Location: Serbia
WilliamL wrote:
The code to just 'open' doesn't work as I wrote it.

Code:
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"filepath$+filename$\","") ; doesn't work

You can't use variables inside strings (yet?).

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

_________________
PB examples collection
pb-osx-globalhotkeys
pb-osx-notifications


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 6:03 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1142
Location: Seattle, USA
Thanks again deseven,

What a sequence in the RunProgram command! :shock:

That did the trick. Now I can use Quicktime for mp4s
Code:
RunProgram("open",~"-b com.apple.QuickTimePlayerX \"" + filepath$ + filename$ + ~"\"","")


and VLC for .ts and .avi files
Code:
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.

_________________
MacBook Pro-r, OSX 10.14.6 , PB 5.73LTS


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 6:28 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jan 12, 2011 3:48 pm
Posts: 229
Location: Serbia
You're welcome!

However, since VLC is not a default application, i suggest checking if it's installed first:
Code:
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.

_________________
PB examples collection
pb-osx-globalhotkeys
pb-osx-notifications


Top
 Profile  
Reply with quote  
 Post subject: Re: Runprogram - QuickTimePlayer
PostPosted: Fri Nov 13, 2020 6:37 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1142
Location: Seattle, USA
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. :)

_________________
MacBook Pro-r, OSX 10.14.6 , PB 5.73LTS


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye