Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

0002378

Suspended
Original poster
May 28, 2017
675
671
My app uses a file dialog (i.e. NSOpenPanel) to allow the user to choose audio files such as mp3's.

Now, the open panel works just fine when browsing through files normally, i.e. it displays all mp3 files and allows them to be selected.

However, if, the search bar within the dialog is used to search for songs, and the results are files that have ID3 metadata (artist/title), then, the dialog's search results hide the file extension. This is a problem because I'm no longer able to select a perfectly valid mp3 file just because it has ID3 metadata and the dialog is hiding its extension in the search view. Please see image below.

OpenPanel.png


This is a bad user experience, because, if the user has a large collection of songs, he/she will definitely use the search feature within the dialog when choosing files, and, if most of his/her songs have ID3 tags, those files' extensions will be hidden, thus preventing the user from selecting those files in the search results.

I checked the behavior of other audio apps like Vox, iTunes, and VLC. Vox has identical behavior to my app, because it filters the allowed file types to audio file types. However, iTunes and VLC allow any kind of files to be chosen, so they get around this problem. However, allowing all file types is a really ugly workaround. I would, ideally, like to be able to filter my allowed file types (by extension), and yet allow the user to select files in search results.

I checked all properties of NSOpenPanel to see if I can tweak the behavior. But, I didn't see anything of help.

Please help. Thank you.
 
  • Like
Reactions: mif
Please post your code. In particular, the allowed types, and any delegate.

If you don't have a delegate, please see this:
https://developer.apple.com/documentation/appkit/nsopensavepaneldelegate

func panel(Any, shouldEnable: URL)

For NSOpenPanel delegates, asks the delegate whether the specified URL should be enabled in the panel. This method is not called for NSSavePanel delegates; all URLs are always disabled.​

Without running an experiment, I can't say whether a panel delegate is applied to search results.


Finally, the circled item in your screenshot doesn't appear to have an extension. Other items with longer names show a ".mp3" extension, but the circled item doesn't, despite having a shorter name and thus plenty of display space to show an extension. Since other files with extensions do actually show those extensions, I'm not so sure the problem is that the search isn't showing extensions. To me, it looks more like the dimmed file lacks an extension.
 
  • Like
Reactions: 0002378
Please post your code. In particular, the allowed types, and any delegate.

Thanks, chown. I tried specifying a delegate and implementing shouldEnable(url). It didn't work. But I've found a proper solution to this, after all !

I was only specifying file extensions before - e.g. "mp3". It didn't work because the search was hiding the file extension because the track had an ID3 artist/title. So, instead of showing up as "01 - Hydropoetry Cathedra.mp3", it was showing up as "Aural Planet - Hydropoetry Cathedra" (i.e. Artist - Title), omitting the extension altogether.

I am now specifying file type UTIs. i.e.AVFileTypeMPEGLayer3, instead of just the extension, so that the dialog can detect the intrinsic type of the file without needing to check its extension. Works like a charm !

Thanks for your help.

Code:
// Old code
static let supportedFileTypes_open: [String] = ["mp3", "m4a", "aac", "aif", "aiff",
"aifc,", "wav", "m3u", "m3u8"]

// New code
static let supportedFileTypes_open: [String] = ["mp3", "m4a", "aac", "aif", "aiff",
"aifc,", "wav", "m3u", "m3u8", AVFileTypeMPEGLayer3, AVFileTypeAIFC,
AVFileTypeAIFF, AVFileTypeAppleM4A, AVFileTypeWAVE]

// Unchanged code
openDialog.allowedFileTypes  = supportedFileTypes_open
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.