
Some time ago I switched to Mac and began to pick up my software for everyday use. The problem arose with the music player. I tried many players, but none of them did not suit me. So I decided to write my own. At the same time, it was interesting for me to try development on Objctive-C for Mac.
As a result, I got a player
Repl , which means "residental":
Audio Player Requirements
Regarding what should be an audio player, I have the following considerations:
')
1. The audio player does not need a graphical interface.
The sound goes in the background, you do not need to look at it, so there is no need to make any graphical interface for the audio player. Of course, the player needs to be managed somehow, but all control can be reduced to just four buttons - the menu, start / pause, the next and previous track.
These buttons fit perfectly in the status bar, where they are always at the click of a mouse. And at the same time there is no need to switch focus from an open application.
2. The audio player does not need its own library.
The organization of the music repository is perfectly done using the file system. In the overwhelming majority of cases, the music collection has a hierarchical structure (for example, Genre - Artist - Album - Track), which is reproduced without any problems using subfolders of the file system. Moreover, you can create a more spreading structure from folders than from a limited set of id3 tags.
In addition, with conventional files it is much more convenient to perform various manipulations, not related to the actual listening. For example, it is much easier to directly copy a couple of folders with files than to pre-export from a library, or to look for exactly where the files displayed in the library are stored.
3. The audio player does not need playlists.
If there is a well-organized, structured collection of tracks in the file system, then simply open the necessary folders for playback. You want - open one album, you want - several different albums, you want - a singer with all his albums.
No need to make a layer between the files and the player, the player should just play the contents of the disk "as is".
Development
Up to this point, I have never programmed for Mac in general and in Objective-C in particular. So I wrote the player in parallel with the study of Objective-C.
As it turned out, there are very few articles on the development of a Mac in Russian on the web. Native EPL documentation could probably give a lot, but it’s too voluminous, I find it difficult to read in English. Most of the information, mainly code samples, I had to draw on English-language resources such as StackOverflow.
I knew exactly what the player should be, how it should look and what should have the functionality. Therefore, I did not have any pondering, design stage. I just found the steps for each emerging question and then wrote the code. In the process, I even wrote a few notes in my LiveJournal - how to set up Xcode, how to put an application icon in the status bar, how to read files, etc. A sort of tutorial for himself.
The most difficult issue was sound reproduction. I started experimenting with the
NSSound class. As I understand it, this is a kind of “standard” class for playing sound in Objective-C. At first, I didn’t manage to make this class reproduce the sound for a long time, then I couldn’t catch the end of the track to start the next one. I started to get the impression that the NSSound class was not intended for use in the player at all, rather, it is needed to play a short sound once, such as a signal about the end of a file upload, or something like that.
Then I decided to try to deal with the
AV Foundation framework, I can write a player on it. However, it somehow happened that I was prompted by a way to make NSSound make sounds, and I learned to catch the end of the track myself. And I made a player based on NSSound.
Unfortunately, this class eats memory with terrible force. A certain amount of memory is allocated for playing each new track, and after the end of the track the memory is not released. Here either I don’t understand something and just crookedly wrote the code, or NSSound is really intended only for one-time reproduction of one fixed sound. I would be extremely grateful if those who were knowledgeable in the question told me how to overcome this problem.
Other issues, such as reading files or creating menus, did not seem difficult to me. Well, no more difficult than any other questions arising from the study of new technology. On the moments of the creation of the player, I also wrote a few notes in LJ.
Result
As a result, I wrote for myself an audio player that completely suits me. And now I want to share the result with everyone.
Repl is an open and completely free player.
All source codes are on Gitkhab , in the same place there is a small list of features which I still want to fasten to Replu.
I will be any comments and suggestions, as well as pull-requests :)
UPD. I did rewrite the player to AVFoundation.
UPD2. This article has been in draft for about a year, so some old comments may already be irrelevant.