QuickTime video player for Cocoa

Mac OSX specific forum
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: QuickTime video player for Cocoa

Post by fsw »

The TouchBar shouldn't matter as the TouchBar items are automatically invoked if a TouchBar is available. If a TouchBar is not available it's not invoked.
Apparently a program with custom TouchBar items should even work on computers without TouchBar as long as macOS 10.12 is used.
Got a custom TouchBar coded with Objective C. It's pretty similar to the StatusBar.
Works nicely.

Thank you for all your input.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: QuickTime video player for Cocoa

Post by fsw »

Found out that it also works with NSApplicationMain; at least with local files.
Not sure why it doesn't work with remote files as:

Code: Select all

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
		<key>NSAllowsArbitraryLoadsInWebContent</key>
		<true/>
	</dict>
is inside the plist file...

Really strange.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: QuickTime video player for Cocoa

Post by fsw »

It works now :!:

The solution is to only add:

Code: Select all

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
and leave NSAllowsArbitraryLoadsInWebContent out :!:
Now remote videos are played.
Finally :!:
:mrgreen:

BTW: NSApplicationMain works beautifully without a NIB :D

I am to provide the public with beneficial shocks.
Alfred Hitshock
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: QuickTime video player for Cocoa

Post by Niffo »

Hi Wilbert and Fsw,

Since QTKit/QTMovie (based on Quicktime 7, wich is 32 bits) is no more supported in MacOS 10.15 Catalina, i am trying to update my custom movie library with AVKit/AVFoundation.
I started using your code Wilbert, but i need to implement more functions like seeking into the video file.
I tryed with "seekToTime" like that but it does nothing :

Code: Select all

   Structure CMTime ;{
      value.q ; Int64_t
      timeScale.l ; Int32_t
      flags.l ; UInt32_t
      CMTimeEpoch.q ; Int64_t
   EndStructure ;}

   Define.CMTime time
   Define.CMTime duration

   CocoaMessage(@duration, CocoaMessage(0, CocoaMessage(0, *p\Player, "currentItem"), "asset"), "duration")
Debug "Duration = " + Int(duration\value * 1000 / duration\timeScale) ; Works OK !

   time\timeScale = duration\timeScale
   time\value = Value * time\timeScale / 1000
   CocoaMessage(0, *p\Player, "seekToTime:@", @time)
Any idea ?
Niffo
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: QuickTime video player for Cocoa

Post by wilbert »

Niffo wrote:Any idea ?

Code: Select all

#kCMTimeFlags_Valid = 1
  
Structure CMTime
  value.q
  timeScale.l
  flags.l
  CMTimeEpoch.q
EndStructure
  
; Move to 30 sec
time.CMTime
time\value = 30000
time\timeScale = 1000
time\flags = #kCMTimeFlags_Valid
CocoaMessage(0, Player, "seekToTime:@", @time)
You forgot to set the flag that the time is valid.
Windows (x64)
Raspberry Pi OS (Arm64)
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: QuickTime video player for Cocoa

Post by Niffo »

Wilbert ... I love you ! <3
Niffo
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: QuickTime video player for Cocoa

Post by Niffo »

For those who would be interested, here is how to :

- Play the media :

Code: Select all

CocoaMessage(0, Player, "play")
- Pause the media :

Code: Select all

CocoaMessage(0, Player, "pause")
- Seek the media

Code: Select all

Structure CMTime ;{
   value.q ; Int64_t
   timeScale.l ; Int32_t
   flags.l ; UInt32_t
   CMTimeEpoch.q ; Int64_t
EndStructure ;}
Define.CMTime time
CocoaMessage(@time, Player, "currentTime")
time\value = Value * time\timeScale / 1000
CocoaMessage(0, Player, "seekToTime:@", @time) ; To be knowed : seekToTime : parameters "toleranceBefore" and "toleranceAfter" can be set to "CMTimeZero" for higher accuracy
- Get the original size of the media

Code: Select all

Define.CGSize size
CocoaMessage(@size, CocoaMessage(0, CocoaMessage(0, Player, "currentItem"), "asset"), "naturalSize") ; Noted as deprecated in Apple docs, should use : CGSize size = [[[movieAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize];
debug size\width
debug size\height
- Change the media volume

Code: Select all

Define.f Volume = Value / 100
CocoaMessage(0, Player, "setVolume:@", @Volume)
- Get the media duration

Code: Select all

Structure CMTime ;{
   value.q ; Int64_t
   timeScale.l ; Int32_t
   flags.l ; UInt32_t
   CMTimeEpoch.q ; Int64_t
EndStructure ;}
Define.CMTime duration
CocoaMessage(@duration, CocoaMessage(0, CocoaMessage(0, Player, "currentItem"), "asset"), "duration")
debug Int(duration\value * 1000 / duration\timeScale)
- Free the media :

Code: Select all

CocoaMessage(0, PlayerView, "setPlayer:", #Null)
CocoaMessage(0, PlayerView, "release")
CocoaMessage(0, Player, "replaceCurrentItemWithPlayerItem:", #Null)
CocoaMessage(0, Player, "release")
Niffo
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: QuickTime video player for Cocoa

Post by wilbert »

It would be nice if PureBasic itself would be updated to use AVPlayer instead of QuickTime for the Movie library.
Windows (x64)
Raspberry Pi OS (Arm64)
Niffo
Enthusiast
Enthusiast
Posts: 500
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: QuickTime video player for Cocoa

Post by Niffo »

+1
viewtopic.php?f=24&t=73941

... but not the time to wait and before that (few years), PB Movie library was not complete/stable. Do not know if it is stable now.
Niffo
Post Reply