📜 ⬆️ ⬇️

The pillars of KDE4. Phonon.


The second pillar, on which KDE4 rests, is no less grandiose and majestic. Phonon is a multimedia API. Just like his sister Solid, Phonon abstracts from a particular sound engine, be it Xine, PulseAudio, GStreamer, DirectShow, or QuickTime. Phonon, by the way, is not part of KDE, although KDE4 uses it very actively. The famous Qt framework for creating cross-platform applications (reads as [kuit], not [kuti]!) Since version 4.4 has built-in support for Phonon.

Why invent a bicycle?


From time immemorial, KDE2.0 has used aRts as a media framework and provides a multimedia API. However, times go and everything changes, and, fortunately or unfortunately, aRts could not stand this race and is no longer being developed . The fact that others would take his place was only a matter of time, and there was less and less time - after all, such a big project was being developed, and everything was nearing the moment of its first release. And which of all the existing options to choose? So that it is modern, so that it supports the necessary functions and so that the same thing happened with aRts?
The answer is simple - do not adapt to one engine, but be ready to work, if not with all, then with many.

What will Phonon give to ordinary users?


Phonon, again, will relieve you of the headache about how and through what to reproduce the sound. For clarity, let's imagine this:
It is necessary that the system notifications are sounded in your two-hundred-watt speakers (hello to neighbors: D), in order for Skype to mumble into your wireless BlueTooth headset, and parents listen to Queen in the next room on a separate stereo system. If you have the necessary number of sound output devices, Phonon in conjunction with the already reviewed Solid will allow you to customize everything in just a few mouse clicks.
For clarity, I will provide a screenshot, of course, not relevant to the example that I described, but still helping you to see the typical Phonon configuration interface in KDE4.

Moreover, the switch is made on the fly, and ideally, not only the reboot, but also the restart of the applications is not needed! Of course, for now everything may not be so smooth, that is, the change now takes effect after the application sound is restarted (in the case of system notifications, restarting KDE4), but this is only for the time being.
And so that there are no special doubts that this is really a universal and cross-platform solution - here is a screenshot of my Windows XP:

As you can see, in this case Phonon uses the DirectShow9 engine. On Mac OS X, QuickTime would be in its place. This is another plus - Phonon uses the engines already installed in the system and adapts to them.

What will Phonon give developers?


A lot of things! How to play a sound file supported by your sound subsystem? Only 4 lines of code - and you're done!
media = new MediaObject(this);
connect(media, SIGNAL(finished()), SLOT(slotFinished()));
media->setCurrentSource("/home/username/music/filename.ogg");
media->play();

In general, Phonon provides not only basic playback functions, but also provides an interface for creating special effects. To work with Phonon, you, as a developer, will need to know only the front-end API. The main objects of Phonon are MediaObject and AudioOutput . The data acquired through the MediaObject should be transferred to the audio output. To do this, use the Phonon :: createPath function , which returns a Path object (path), into which you can then enter special effects that will affect the sound signal.

If, in addition to sound, video is also used, then an additional branch is added to the scheme. As a result, we get something like this:

As you can see, working with sound becomes as easy and natural as writing any other code in Qt and using kdelibs.
I only touched on the edge of what becomes available to the developer, a more serious immersion awaits you while reading the API documentation on the KDE project site, as well as the relevant Qt help topics , also available through the Qt Assistant program.
For users, the only thing left is the joy of using all these blessings of humanity, easily changing the settings of the sound output when necessary.
On this, perhaps, complete the post. If it seemed to someone a little, or there were questions - write comments, write in a personal, write on soap - my_nik <on> mail.ru. I will be glad to hear feedback and suggestions.

Information taken from the official site of the Phonon project , from the official Qt help . As always, your own experience with Phonon has helped - on the KDE-apps you can find the trayplayer application. It's not mine, but it's pretty easy to figure it out. I screwed the replay to it, scrolling back the option, and purely out of curiosity translated this project to CMake, divided the classes into different files and began to implement the basic playlist.

Post on WeLinux.ru .

')

Source: https://habr.com/ru/post/54627/


All Articles