Post

Replies

Boosts

Views

Activity

ITLibrary.mediaFolderLocation
I see ITLibrary.musicFolderLocation is deprecated. Is ITLibrary.mediaFolderLocation also deprecated? The reason I ask is the result to my call to ITLibrary.mediaFolderLocation is file:///Volumes/Music%201/iTunes/iTunes%20Media/. I have no idea where this URL is coming from! The thing is I am running Monterey and iTunes was changed to Music when Catalina was released, so the location should at least be file:///Users/carroll/Music/Media/Music on a default setup. Someone recommended in another post to check com.apple.music.plist but that file doesn't even exist on my machine. I know the info is being stored somewhere because I create another Music Library on an external volume using the option-click method and when I query the library it is showing the new library. I would like to show the URL of the currently selected Music.app library in my own app so the user knows which library they are working with. The new library exists at "file:///Volumes/Dummy/Music/Test" I did a search with finder for "plist" and added a Contents rule for "Dummy/Music" and nothing comes up, so I do not know where URL for the currently selected Music.app library is being stored and if I can get it. I wonder if I should be looking to switch to MusicKit?
0
0
705
Mar ’23
Word Wrapping Bug in NSTextField?
I am having an issue with text not wrapping correctly if there is a single quote, or macOS ASCII Extended Character #213 (shift+opt.+]) in a string. Apple does not escape the media item title string when it is retrieved through the iTunesLibrary framework, which is where I ran into this problem. As you can see in the example below, the first string is exactly how it comes from the iTunesLibrary using the framework API call. The second string is with the single quote is escaped, the third string is if I use macOS Extended ASCII Character code 213, and the fourth string is if I use a tilde. The tilde is not the right character to use in this situation, but it is the only one that correctly wraps the text in the cell. I worked on this for 6-8 hours to figure it out before posting this on StackOverflow. This is the result I get: Anyone else get the same result running this? Do I need to report this as a bug? Here's my code example: ViewController.swift import Cocoa     override func viewDidLoad() {         super.viewDidLoad()         self.view.frame.size = NSSize(width: 616, height: 184)         // Strings         let strings: Array<String> = ["I Keep Forgettin' (Every Time You're Near)","I Keep Forgettin\' (Every Time You're Near)","I Keep Forgettin’ (Every Time You're Near)","I Keep Forgettin` (Every Time You're Near)"]         // Formatting         let foreground = NSColor.purple.cgColor         let paragraphStyle = NSMutableParagraphStyle()         paragraphStyle.alignment = .center         paragraphStyle.lineBreakMode = .byWordWrapping         paragraphStyle.tabStops = .none         paragraphStyle.baseWritingDirection = .leftToRight         guard let font = NSFont(name: "Helvetica", size: 28.0) else { return }         // Labels         var labels: Array<NSTextField> = [NSTextField]()         for i in 0..<strings.count {             let label = NSTextField(frame: NSRect(x: 20+(i*144), y: Int(self.view.frame.minY)+20, width: 144, height: 144))             label.cell = VerticallyCenteredTextFieldCell()             label.wantsLayer = true             label.layer?.borderColor = NSColor.purple.cgColor             label.layer?.borderWidth = 0.5             label.layer?.backgroundColor = NSColor.lightGray.cgColor             label.alphaValue = 1             let fontSize = bestFontSize(attributedString: NSAttributedString(string: strings[i], attributes: [.font: font, .paragraphStyle: paragraphStyle]), size: CGSize(width: 136, height: 136))             label.attributedStringValue = NSAttributedString(string: strings[i], attributes: [.font: font.withSize(fontSize), .foregroundColor: foreground, .paragraphStyle: paragraphStyle])             labels.append(label)             self.view.addSubview(labels[i])         }     } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } func bestFontSize(attributedString: NSAttributedString, size: CGSize) -> CGFloat { // Create a property to hold the font and size var font: NSFont? // Get the font information from the string attibutes attributedString.enumerateAttribute(.font, in: NSRange(0..<attributedString.length)) { value, range, stop in if let attrFont = value as? NSFont { font = attrFont } } if font == nil { return 0 } // Get any paragraph styling attributes var paragraphStyle: NSMutableParagraphStyle? attributedString.enumerateAttribute(.paragraphStyle, in: NSMakeRange(0, attributedString.length)) { value, range, stop in if let style = value as? NSMutableParagraphStyle { paragraphStyle = style } } if paragraphStyle == nil { return 0 } // Create a sorted list of words from the string in descending order of length (chars) of the word let fragment = attributedString.string.split(separator: " ").sorted() { $0.count > $1.count } // Create a bounding box size that will be used to check the width of the largest word in the string var width = String(fragment[0]).boundingRect(with: CGSize(width: .greatestFiniteMagnitude, height: size.height), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font!, .paragraphStyle: paragraphStyle!], context: nil).width.rounded(.up) // Create a bounding box size that will be used to check the height of the string var height = attributedString.string.boundingRect(with: CGSize(width: size.width, height: .greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font!, .paragraphStyle: paragraphStyle!], context: nil).height.rounded(.up) while height >= size.height || width >= size.width { guard let pointSize = font?.pointSize else { return 0 } font = font?.withSize(pointSize-0.25) width = String(fragment[0]).boundingRect(with: CGSize(width: .greatestFiniteMagnitude, height: size.height), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font!, .paragraphStyle: paragraphStyle!], context: nil).width.rounded(.up) height = attributedString.string.boundingRect(with: CGSize(width: size.width, height: .greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font!, .paragraphStyle: paragraphStyle!], context: nil).height.rounded(.up) } return font!.pointSize } } VerticallyCenteredTextFieldCell.swift import Cocoa class VerticallyCenteredTextFieldCell: NSTextFieldCell { // https://stackoverflow.com/questions/11775128/set-text-vertical-center-in-nstextfield/33788973 - Sayanti Mondal func adjustedFrame(toVerticallyCenterText rect: NSRect) -> NSRect { // super would normally draw from the top of the cell var titleRect = super.titleRect(forBounds: rect) let minimumHeight = self.cellSize(forBounds: rect).height titleRect.origin.y += (titleRect.height - minimumHeight) / 2 titleRect.size.height = minimumHeight return titleRect } override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { super.drawInterior(withFrame: adjustedFrame(toVerticallyCenterText: cellFrame), in: controlView) } }
2
0
1.3k
Nov ’22
Sending Presentation to multiple displays via Airplay
Before I spend money on Roku devices that support Airplay, I wanted to first ask: Can Airplay simultaneously cast to multiple Airplay devices during a Keynote presentation? If not, is there a programatic solution like writing a system service to allow a multicast type thing to send the extended display out to multiple Airplay display devices? I use my MacBook Air Silicon to do Keynote presentations in presenter mode through an extended display. My main display on the laptop can have multiple windows open that I use for reference and the Keynote presentation is on the extended display. Some of the facilities I go into are not properly wired with a splitter to send my presentations out to multiple displays for easy view by my attendees.
0
0
746
Jul ’22
ITLibMediaItemLyricsContentRating availability in Music app
Not really sure if this post belongs here, but it pertains to the iTunesLibrary Framework. While looking through the iTunesLibrary framework, I came across the subject constant. However, I do not know how to set this within the Music app. Is this a legacy feature of iTunes before Apple switched to Music with Catalina? I looked through the preferences for Music and I do not see where to turn this feature on, nor is it available as a display column in Music while viewing songs as a list. I have been managing my music by appending (Clean) for a non-explicit version of a song with explicit lyrics, or (Explicit) if a non-explicit version is not available. It would be nice to not have to do this if this feature can be turned on in the Music app.
0
0
720
May ’22
How to properly dispose of Connected Display Window and View?
I posted this question on SO as well. I have code that opens a window and displays a view on a connected display. My goal is to detect a connection/disconnection of a connected display and show/remove the view accordingly. I have that part working fine. The problem I am having is closing the window upon disconnection/interruption, but then if a subsequent connection is made, and upon creating the window and view again, I get a EXC_BAD_ACCESS error. I tried a different approach by setting the connectedDisplayWindow and connectedDisplayView to nil, after calling close() on the window when a connected display is removed. Maybe I am misunderstanding the close() method? Apple Documentation If the window is set to be released when closed, a release message is sent to the object after the current event is completed. For an NSWindow object, the default is to be released on closing, while for an NSPanel object, the default is not to be released. You can use the isReleasedWhenClosed property to change the default behavior... Just to make sure, I tried setting the isReleasedWhenClosed to true, but it did not change the problem. The other thing I see in the console is about seven repeated error strings immediately upon disconnection of the connected display: 2022-04-10 10:28:11.044155-0500 External Display[95744:4934855] [default] invalid display identifier 67EE0C44-4E3D-3AF2-3447-A867F9FC477D before the notification is fired, and one more after the notification occurs: 2022-04-10 10:28:11.067555-0500 External Display[95744:4934855] [default] Invalid display 0x4e801884. Could these be related to the issues I am having? See example code in attachments. ViewController.swift ConnectedDisplayView.swift I commented out the nil settings for the connectedDisplayWindow and connectedDisplayView objects and the error at @main in AppDelegate went away, but then I get an error when trying to reinitialize the connectedDisplayWindow if the connected display is removed or the connection is momentarily interrupted.
1
0
1.4k
Apr ’22
Is com.apple.AMPLibrayAgent not used by Apple Music.app?
I ran into a problem with Catalina (and later) and the new Muisc.app while using the ITLibrary framework. The ITLibrary.mediaFolderLocation and ITLibrary.musicFolderLocation methods no longer return the correct values. In fact, the fields in UserDefaults have not been updated on my system since moving from iTunes to Music because the library pointed to by “iTunes-media-folder-url“ points to an old iTunes library within the com.apple.AMPLibraryAgent suiteName. After doing some digging and performing a dump of all UserDefaults and comparing them before and after manually switching my Music Library by option+Clicking the Music.app icon, there are no changes between the two dumps with respect to the Music.app. This leads me to believe the Music.app is not storing it's information in UserDefaults like iTunes used to. Has anyone else run into this problem? Is there somewhere else one can look into the system to find what the last selected Music library was? I'm looking for a reliable workaround to know the location of the currently selected Music library.
1
0
1.5k
Mar ’22
Error 2003332927 (who?) in CoreMediaIO module
Since upgrading to macOS 12.0.1 from 11.6 I am now getting this strange error in my debug console while running in Xcode 13.1: 2021-12-09 08:25:22.251548-0600 Test Player[66635:564515] [aqme]    MEMixerChannel.cpp:1639 client <AudioQueueObject@0x7fd258943000; [0]; play> got error 2003332927 while sending format information Through reading other posts and finding a site that shows information about various Apple API Errors, that site does not explain where to look or how to track down this error. It appears the error is coming from CoreMediaIO specifically in CMIOHardware.h. How do I get to the root of this error and fix it? It appears to not affect the compiling and running of the app, but I do not like to see these kinds of errors popping up.
5
2
2.5k
Dec ’21
Opening NSWindow on a connected display
I came across this question on S.O. while searching for how to open a new NSWindow / NSView on a connected display. I converted the obj-c code to Swift as well as I could, but I cannot get it to work. I have the method set up inside an IBAction and I linked the action to a button I placed in the ViewController's View titled "Show External Display." What am I doing wrong? Is there a good resource that can help me for working with connected displays using Cocoa/AppKit? I've read the docs, but still can't seem to get this working. import Cocoa class ViewController: NSViewController { var externalDisplay: NSScreen? var fullScreenWindow: NSWindow? var fullScreenView: NSView? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } @IBAction func showExternalDisplayButtonClicked(sender: Any?) { // Open a window on the external display if present if NSScreen.screens.count > 1 { externalDisplay = NSScreen.screens.last let externalDisplayRect = externalDisplay!.frame fullScreenWindow = NSWindow(contentRect: externalDisplayRect, styleMask: .borderless, backing: .buffered, defer: true, screen: externalDisplay) fullScreenWindow!.level = .normal fullScreenWindow!.isOpaque = false fullScreenWindow!.hidesOnDeactivate = false fullScreenWindow!.backgroundColor = .red let viewRect = NSRect(x: 0, y: 0, width: externalDisplay!.frame.width, height: externalDisplay!.frame.height) fullScreenView = NSView(frame: viewRect) fullScreenWindow!.contentView = fullScreenView fullScreenWindow!.makeKeyAndOrderFront(self) } } }
3
0
976
Sep ’21
NSAppearance not forcing the named appearance onto my windows
I am having an issue getting NSAppearance to work as described here in the documentation. I am using Xcode 12.5.1 in macOS Big Sur 11.5.1. In my system preferences I have my computer set to Dark Aqua all the time. However, reading the linked document I should be able to force all my windows programmatically to use Aqua, but that is not the result I am getting with this. import AppKit class ViewController: NSViewController {     var progressBar: NSProgressIndicator?     weak var timer: Timer?     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view. // Force the appearance for testing         self.view.appearance = NSAppearance(named: .aqua)         let progressFrame = NSRect(x: self.view.frame.midX - view.frame.width / 2 + 30, y: self.view.frame.midY - 10, width: self.view.frame.width - 60, height: 20)         progressBar = NSProgressIndicator(frame: progressFrame)         self.view.addSubview(progressBar!)         progressBar?.isHidden = false         progressBar?.isIndeterminate = false         progressBar?.doubleValue = 0         progressBar?.maxValue = 1.0         startTimer()     }     func startTimer() {         timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)     }     @objc func updateProgress() {         if progressBar!.doubleValue < 1.0 {             progressBar?.doubleValue += 0.02         } else {             timer?.invalidate()             progressBar?.doubleValue = 0             progressBar?.isHidden = true         }     } } Am I missing something?
2
0
818
Aug ’21
Override info.plist value at runtime
I'm testing my user interface in light and dark mode settings and I have the "NSRequiresAquaSystemAppearance" set in my info.plist file and I was wondering if there is a way to override that setting at runtime, rather than having to constantly go to my info.plist and setting it manually between runs? I'm searching for something like NSApp.effectiveAppearance.setValue(true, forKey: "NSRequiresAquaSystemAppearance")
1
0
3.8k
Aug ’21
Markdown in Xcode 12.5.1
I'm trying to document my code using the Markdown, but it doesn't matter what I do, I am not seeing what I've typed show up when I ctrl-click a function and left click Show Quick Help. Quick Help shows the parameters of the function, but it does not show the function description I typed or the description for the parameters that I typed. Is there something I am doing wrong or I've not set within Xcode? I went through the preferences and didn't see anything that appeared to affect displaying of Markdown.
1
0
1.3k
Aug ’21
Apple Document - Creating a Basic Video Player
I followed this - https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_macos document to try and create a streaming video player in a macOS app and I am getting nothing but errors. Here's my code: import Cocoa import AVFoundation import AVKit class ViewController: NSViewController {   @IBOutlet var playerView: AVPlayerView!       override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view.     guard let url = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8") else {         return       }     // Create a new AVPlayer and associate it with the player view     let player = AVPlayer(url: url)     playerView.player = player   }   override var representedObject: Any? {     didSet {     // Update the view, if already loaded.     }   } } When I run the code, I get the following errors in the console: 2021-03-27 09:24:44.920720-0500 Streamer[27640:1013041] [plugin] AddInstanceForFactory: No factory registered for id CFUUID 0x600002e22b60 F8BB1C28-BAE8-11D6-9C31-00039315CD46 2021-03-27 09:24:45.042030-0500 Streamer[27640:1013040] validateSessionInfo: bundleID is invalid. Please specify the bundleID for kRTCReportingSessionInfoClientBundleID 2021-03-27 09:24:45.042972-0500 Streamer[27640:1013054] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-27 09:24:45.043046-0500 Streamer[27640:1013054] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-27 09:24:45.071473-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.072119-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.072665-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.073682-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.074877-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.155189-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.155577-0500 Streamer[27640:1013055] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-27 09:24:45.168271-0500 Streamer[27640:1013081] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service 2021-03-27 09:24:45.169487-0500 Streamer[27640:1013081] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:7 Err:-1 Errno:1 Operation not permitted 2021-03-27 09:24:45.169606-0500 Streamer[27640:1013081] [connection] nw_resolver_create_dns_service_locked [C1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563) 2021-03-27 09:24:45.170098-0500 Streamer[27640:1013081] Connection 1: received failure notification 2021-03-27 09:24:45.171183-0500 Streamer[27640:1013081] Connection 1: failed to connect 10:-72000, reason -1 2021-03-27 09:24:45.171229-0500 Streamer[27640:1013081] Connection 1: encountered error(10:-72000) 2021-03-27 09:24:45.172760-0500 Streamer[27640:1013055] Task 9413249A-2C3E-4A40-B71B-394F5E95D197.1 HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000]) 2021-03-27 09:24:45.174833-0500 Streamer[27640:1013084] Task 9413249A-2C3E-4A40-B71B-394F5E95D197.1 finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x6000020cb030 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask 9413249A-2C3E-4A40-B71B-394F5E95D197.1, _NSURLErrorRelatedURLSessionTaskErrorKey=(   "LocalDataTask 9413249A-2C3E-4A40-B71B-394F5E95D197.1" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8, NSErrorFailingURLKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8, _kCFStreamErrorDomainKey=10} 2021-03-27 09:24:45.175255-0500 Streamer[27640:1013055] validateSessionInfo: bundleID is invalid. Please specify the bundleID for kRTCReportingSessionInfoClientBundleID 2021-03-27 09:24:45.176213-0500 Streamer[27640:1013040] sendOneMessageWithSessionInfo: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-27 09:24:45.176282-0500 Streamer[27640:1013081] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-27 09:24:45.207079-0500 Streamer[27640:1012591] Metal API Validation Enabled 2021-03-27 09:24:45.233220-0500 Streamer[27640:1013081] fopen failed for data file: errno = 2 (No such file or directory) 2021-03-27 09:24:45.233272-0500 Streamer[27640:1013081] Errors found! Invalidating cache... 2021-03-27 09:24:45.288729-0500 Streamer[27640:1013081] fopen failed for data file: errno = 2 (No such file or directory) 2021-03-27 09:24:45.288805-0500 Streamer[27640:1013081] Errors found! Invalidating cache...
2
0
2.2k
Mar ’21
Apple Music on Big Sur
I have written a macOS app that uses the iTunesLibrary framework. The app utilizes the media item's persistentID as provided by the iTunesLibrary framework to manage the settings for the track within my app. I develop this app on an iMac (late 2015) using Xcode 12.4. I then distribute the app to my MacBook Air (2020 M1). I use Rsync to synchronize any music files from the Music Library that have been modified (lyrics/cover art, etc.), including the Music/Music/Music Library.musiclibrary database. The need for the persistentID of the media item to remain consistent from one machine to the other is paramount for the app to work. Otherwise, the app is broken. This is why I am Rsyncing the library database. I did not have an issue with this on macOS Big Sur 11.1 and earlier. The persistentID was being preserved on both machines and the software worked perfectly. However, for some reason now the persistentID is not being persistent across machines. It is like the Music database on the Macbook Air is being touched/modified somehow and the persistentID of the media item is being changed before I even launch the Music app. Upon Rsyncing the Music/Music/Music Library.musiclibrary database to the Macbook Air, then launching my app the persistentID does not exist. I then open Apple's Music app and the track is most definitely there, but the persistentID is now different. Is Apple doing something with the Music app database in these latest releases? I have tried deleting everything from the Music/Music folder and Rsyncing the entire Music/Music folder from my iMac to the Macbook Air (a 2+ hour task), and the problem remains. I have turned on visibility of hidden folders and I cannot see anything else that could be causing this issue in the Music folder. Should I be looking somewhere else?
0
0
707
Feb ’21