Qt phonon Multimedia Framework

Source: Internet
Author: User
Tags gstreamer

What is phonon? Qt provides a set of multimedia frameworks starting from version 4.4 and supports multimedia playback. Currently, the implementation of the multimedia playback GUI in QT 4.6 mainly depends on the phonon framework. In fact, there is a multimedia module in QT. The help document describes the implementation of the underlying multimedia playback function, in general, the upper-layer Interface phonon module is more suitable for implementing these functions. Phonon was initially a KDE-based project that provided a framework for developing audio and video applications. The application does not need to care about the implementation of multimedia playback (such as gstreamer and xine). It only needs to call the corresponding interface, but this requires a transit, called backend. Qt also uses phonon to implement multi-media playback on the exaggerated platform.

The playback process of multimedia files includes:File Reading, shunting, decoding, and output.


These methods vary in different systems, such as DirectX in windows, gstreamer in Linux, xine, and QuickTime in Mac. The phonon in QT, as a multimedia solution of the exaggerated platform, should block these differences for users. In fact, it is not good enough, because you still need to install the corresponding backend plug-in to complete the playback task.


You can see that the application phonon framework is essentially divided into four parts,Your program, phonon library, phonon backend plug-in (phononon_backend), Real backend. Phonon does nothing,He only provides a set of API Interfaces,This interface can be called by your program, and also provides a standard for compiling backend plug-ins.. The program does not know who will put my MP3, who will decode my video, and which device is playing.
Similarly, the phonon library does not know. It just searches for plug-ins that comply with its own specifications. And tell these plug-ins what the current program sends instructions, the current media status and information returned from the plug-in to the program. WhileThe backend is the part that actually reads, decodes, and plays the media. They correspond to backend plug-ins one by one.. The backend can be in any form, as long as you write the corresponding backend plug-in. Therefore, you must first do three things to use phonon:
(1) compile your phonon Library: In general, QT does not compile by default. You only need to configure parameters after configuring configure, and then enter the phonon folder separately for compilation.
(2) compile your phonon backend plug-in: QT provides an available backend plug-in for the three platforms, which is placed in the SRC \ plugins \ phonon directory. Go to the directory compilation page. QT automatically selects the backend plug-in of your current system. (Phonon backend plugin cocould not be loaded is not done in this step)
If you are a mingw user, sorry. In Windows, QT only providesDirectShowThis backend plug-in, which calls the dx sdk, can only be compiled by VC. Of course, you actually have a better choice. For example, with this phonon-VLC-mplayer plug-in, you can use mplayer as your backend, abandon bloated Vs and read ID3v2 will cause errors in DirectShow (in fact, it cannot blame DirectShow. DirectShow is also a framework, and decoding depends on the decoder and filter of the system, the player I use is too green, so DirectShow is very weak)
(3) You must ensure that your backend works normally: For the backend that QT provides the default plug-in, it is basically not a problem. But if you want to be an embedded player? Well, a big problem. According to people who have transplanted gstreamer, this is annoying. The QT embedded player is still a solid qprocess + mplayer slave mode! (The New qt4.5 indicates that the DirectShow backend plug-in on CE is provided. If you are interested, try it)
After completing the above three points, you can take the mediaplayer in the demo for testing. If the test is successful, you can easily use QT to implement your own media playback. Want more advanced operations, such as coding, mixing, and storing media files? Wait until phonon is updated. Now,Phonon is just a sound transmitter that can't do anything..

As mentioned above, if you want to run a program written using phonon in QT, you must meet the following conditions: QT basic library, QT phonon library, phon_backend (backend plug-in), and multimedia playing background. The following uses the Linux (Fedora 12) system, QT 4.6, and mplayer as an example. If the QT basic library has been installed, phonon is not installed by default. We will introduce the installation of phonon and backend plug-ins.
1. Install the phonon Library:
Go to the phonon directory of the source code, such as "/usr/src/qt-everywhere-opensource-src-4.6.0/src/phonon", the actual code is not inside, from phonon. the Pro file shows that the source code is in "/src/3 rdparty/phonon", but does not affect compilation. Enter "make; make install" on the terminal. If an error occurs during installation, You can manually copy the files in lib and include to the installation directory.
2. backend plug-in installation:
(1) download phonon-mplayer.
Address: http://websvn.kde.org/trunk/playground/multimedia/phonon-backends/mplayer/
Use SVN to download: SVN Co SVN: // anonsvn.kde.org/home/kde/trunk/playground/multimedia/phon-backends/mplayer
(2) return to the phonon-mplayer directory and compile (qmake; Make) to generate the phonon_backend/libphonon_mplayer.so dynamic link library.
(3) Copy libphon_mplayer.so to $ qtdir/plugins/phon_backend/
Note: in Linux, QT only supports gstreamer by default. However, mplayer is used as an example because it is easy to install and supports a full range of file formats. The backend plug-in of gstreamer can be directly located in the "/usr/lib64/kde4/plugins/phonon_backend" directory of the system (if it has been installed from the source ).
3. Test
In the example of examples/phonon/qmusicplayer, there is a problem with using mplayer to play back-end concerts. Here demos/qmediaplayer is used.
You can also use a simple example as follows:
# Include <qtgui>
# Include <phonon/mediaobject>
# Include <phonon/videoplayer>
# Include <phonon/backendcapabilities>
Int main (INT argv, char ** ARGs)
{
Qapplication app (argv, argS );

Phonon: mediaobject * Music =
Phonon: createplayer (phonon: musiccategory,
Phonon: mediasource ("/home/dlw/music/mxshfce "));
Music-> play ();
/* Play the video
Phonon: mediaobject * Music =
Phonon: createplayer (phonon: videocategory,
Phonon: mediasource ("/Media/dlw/movie/One. Night. In. Supermarket. Avi "));
Music-> play ();
*/
Return app.exe C ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.