Post

Replies

Boosts

Views

Created

FYI: Playing a movie using AVPlayer in Big Sur
took a bit of experimenting... import AVKit    //  macOS & iOS class ViewController_myShow: NSViewController {          @IBOutlet var myMOV: AVPlayerView! 10.          override func viewDidLoad() {         super.viewDidLoad()                  let playerView = AVPlayerView() 20. 21.         playerView.translatesAutoresizingMaskIntoConstraints = false 22. 23.         view.addSubview(playerView) 24. 25. 26. 27.         playerView.leadingAnchor.constraint  (equalTo: view.safeAreaLayoutGuide.leadingAnchor ).isActive = true 28. 29.         playerView.trailingAnchor.constraint (equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true 30. 31.         playerView.topAnchor.constraint      (equalTo: view.safeAreaLayoutGuide.topAnchor     ).isActive = true 32. 33.         playerView.bottomAnchor.constraint   (equalTo: view.safeAreaLayoutGuide.bottomAnchor  ).isActive = true 34. 35. 36. 37.         playerView.controlsStyle = .floating 38. 39.         playerView.showsFrameSteppingButtons   = true 40. 41.         playerView.showsFullScreenToggleButton = true 42. 43.          44. 45.         guard let path = Bundle.main.url(forResource: "myMovie", withExtension: "mov") else { return } 46. 47. 48. 49.         let player = AVPlayer(url: path) 50. 51.             playerView.player = player 52. 53.         playerView.player?.play()   54. 55.     } 56. 57. } The StoryBoard:AttributesInspector:AVPlayerView settings don't work for me... exactly. I had to set StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:none then include lines 37-41 in my code. The default is StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:inline which appears on screen but does nothing, i.e., no control. Line 21 is also required to be false. The .mov file can be File:AddFilesTo 'd or copied to Assets.xcassets see also: Developer Forum: "can't get extremely simple macOS video player to work..." https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_macos 			
1
0
1.1k
Jan ’21
SceneKits future
I have developed an app using SceneKit since Swift came out. Now SwiftUI is out and uses structs rather than classes. SceneKit is a cascade of classes. As a newbie, I am concerned that my code might be obsolete through depreciations soon after publication and I'd rather get ahead of the issues now. So, is SceneKit long-term viable? My first attempts at converting my custom classes to structs seems impossible without Apple leading the way. If I understand correctly, I can make a struct whose only member is an instance of a class, but the benefits of the struct, e.g., minimal memory, processing time, etc., are lost.
13
0
8.1k
Mar ’20
swift Process() return values
How do I access a returned value from a Process(), in this case 'which'... var sips_path : String? //MARK: locate sips on local machine let which_sips = Process() which_sips.executableURL = URL(fileURLWithPath: "which") which_sips.arguments = ["sips"] do { sips_path = try which_sips.run() } catch let error as NSError { sips_path = "/usr/bin/sips"; print("Failed to execute which_sips", error) }line 8. gets compiler error "Cannot assign value of type '()' to type 'String?'" I believe, but cannot prove, 'which' returns a string. .run() throws and throws are for errors only, right? So where is the result of calling which?It seems I should use a closure to use $0 but it's already in one...line 9. intends to assign a default path.
13
1
7.8k
Mar ’20
How to Hide/Show StackView form code
As stated in the title, I want to hide or show a StackView when a menu item is selected, which in turn changes a global variable. How do I access the identity or handle of the StackView?
Replies
2
Boosts
0
Views
897
Activity
Aug ’21
FYI: Playing a movie using AVPlayer in Big Sur
took a bit of experimenting... import AVKit    //  macOS & iOS class ViewController_myShow: NSViewController {          @IBOutlet var myMOV: AVPlayerView! 10.          override func viewDidLoad() {         super.viewDidLoad()                  let playerView = AVPlayerView() 20. 21.         playerView.translatesAutoresizingMaskIntoConstraints = false 22. 23.         view.addSubview(playerView) 24. 25. 26. 27.         playerView.leadingAnchor.constraint  (equalTo: view.safeAreaLayoutGuide.leadingAnchor ).isActive = true 28. 29.         playerView.trailingAnchor.constraint (equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true 30. 31.         playerView.topAnchor.constraint      (equalTo: view.safeAreaLayoutGuide.topAnchor     ).isActive = true 32. 33.         playerView.bottomAnchor.constraint   (equalTo: view.safeAreaLayoutGuide.bottomAnchor  ).isActive = true 34. 35. 36. 37.         playerView.controlsStyle = .floating 38. 39.         playerView.showsFrameSteppingButtons   = true 40. 41.         playerView.showsFullScreenToggleButton = true 42. 43.          44. 45.         guard let path = Bundle.main.url(forResource: "myMovie", withExtension: "mov") else { return } 46. 47. 48. 49.         let player = AVPlayer(url: path) 50. 51.             playerView.player = player 52. 53.         playerView.player?.play()   54. 55.     } 56. 57. } The StoryBoard:AttributesInspector:AVPlayerView settings don't work for me... exactly. I had to set StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:none then include lines 37-41 in my code. The default is StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:inline which appears on screen but does nothing, i.e., no control. Line 21 is also required to be false. The .mov file can be File:AddFilesTo 'd or copied to Assets.xcassets see also: Developer Forum: "can't get extremely simple macOS video player to work..." https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_macos 			
Replies
1
Boosts
0
Views
1.1k
Activity
Jan ’21
SceneKits future
I have developed an app using SceneKit since Swift came out. Now SwiftUI is out and uses structs rather than classes. SceneKit is a cascade of classes. As a newbie, I am concerned that my code might be obsolete through depreciations soon after publication and I'd rather get ahead of the issues now. So, is SceneKit long-term viable? My first attempts at converting my custom classes to structs seems impossible without Apple leading the way. If I understand correctly, I can make a struct whose only member is an instance of a class, but the benefits of the struct, e.g., minimal memory, processing time, etc., are lost.
Replies
13
Boosts
0
Views
8.1k
Activity
Mar ’20
swift Process() return values
How do I access a returned value from a Process(), in this case 'which'... var sips_path : String? //MARK: locate sips on local machine let which_sips = Process() which_sips.executableURL = URL(fileURLWithPath: "which") which_sips.arguments = ["sips"] do { sips_path = try which_sips.run() } catch let error as NSError { sips_path = "/usr/bin/sips"; print("Failed to execute which_sips", error) }line 8. gets compiler error "Cannot assign value of type '()' to type 'String?'" I believe, but cannot prove, 'which' returns a string. .run() throws and throws are for errors only, right? So where is the result of calling which?It seems I should use a closure to use $0 but it's already in one...line 9. intends to assign a default path.
Replies
13
Boosts
1
Views
7.8k
Activity
Mar ’20