Page 2 of 2

Re: QuickTime video player for Cocoa

Posted: Thu Jun 29, 2017 2:43 pm
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.

Re: QuickTime video player for Cocoa

Posted: Sat Jul 01, 2017 9:46 pm
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.

Re: QuickTime video player for Cocoa

Posted: Sun Jul 02, 2017 12:21 am
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

Re: QuickTime video player for Cocoa

Posted: Wed Nov 06, 2019 3:38 pm
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 ?

Re: QuickTime video player for Cocoa

Posted: Wed Nov 06, 2019 6:42 pm
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.

Re: QuickTime video player for Cocoa

Posted: Thu Nov 07, 2019 4:11 pm
by Niffo
Wilbert ... I love you ! <3

Re: QuickTime video player for Cocoa

Posted: Fri Nov 08, 2019 6:28 pm
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")

Re: QuickTime video player for Cocoa

Posted: Fri Nov 08, 2019 6:47 pm
by wilbert
It would be nice if PureBasic itself would be updated to use AVPlayer instead of QuickTime for the Movie library.

Re: QuickTime video player for Cocoa

Posted: Fri Nov 08, 2019 6:51 pm
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.