PDA

View Full Version : How to play MP3,WAV,OGG,FLAC,MP4,M4A ?



Bong.Da.City
31st August 2010, 00:07
I want to a non-GUI application play on the background ( not from a player ). So with this command


canberra-gtk-play -f /home/babulas/Desktop/1.ogg


i can play only ogg and wav files... Is there any way so i can play all the audio types i mention before ( MP3,WAV,OGG,FLAC,MP4,M4A ) ? I have heard about SDL Libraries but for QtAudioOutput as well... What do you suggest to me and please tell me how to do it... Thanx anyway..!;)

ChrisW67
31st August 2010, 03:20
Clearly, nothing in Qt has much to do with the GTK application or SDL you refer to in the post. Read the Phonon Overview in Assistant and judge for yourself whether Qt can be used to do what you want. You will want to install the relevant GStreamer modules on your Linux machine to support other formats. On Windows I assume you get access to whatever can be played by the codecs installed on the system.

Bong.Da.City
31st August 2010, 08:34
Ok i had read the phonon review.. But nowhere it says the exact function to open those audio files... Could anybody just tell me what libraries should i download and how to make all this work? :/

wysota
31st August 2010, 08:53
I have a suggestion... Install every every possible package in your distribution. Then you'll know for sure that you have installed those required ones as well. And while it is all installing, please read Phonon Overview again, especially the "Playback" and "Installing Phonon" sections. If you have some specific questions afterwards, come back here and ask them.

Bong.Da.City
31st August 2010, 09:20
I have installed the libraries you know.... But i couldn't include phonon... AND.. i had seen the playback but because i cannot include Phonon it says that phonon is not a type name...

Talei
31st August 2010, 10:25
No You didn't fallow advice given to You by wysota, because there is IDENTICAL example explaining HOW TO do EXACTLY what You want in examples directory.
See qtDir/examples/phonon/qmusicplayer.

hakermania
31st August 2010, 10:42
I would also wanted to play a sound file in my app. It sounds very cool. Unfortunately the example doesn't work...:(

Talei
31st August 2010, 11:06
WinXp, qt 4.6.3, build it right now on debug, everything works (ogg, wav, mp4, ... ). So I don't know what doesn't work for You, mostly because You didn't say where the problem lies.
Phonon uses backends, for Win - DirectShow, for Lin GStreamer, MacS QuickTime. If Your application build successful and You don't see wideo, hear sound that means that You don't have appropriate codec in Your system. (use Phonon::ErrorState to determine what's wrong)
Most problem on windows came from the ffdshow codec installed. I personally use K-Lite codec pack, because they works pretty well with phonon/wmp.

Bong.Da.City
31st August 2010, 11:38
Think that hakermania and me have Unix as i can see from his logo...

hakermania
31st August 2010, 12:08
@Bong.Da.City search synaptic for phonon and in the quixk search type library. install all the packages except for them that say perl.

@public Ok, I installed the proper packages and now it compiled fine, but it doesn't play MP3. It does play WAV and OGG properly but it cannot play MP3......:eek:
http://a.imageshack.us/img843/394/screenshotfr.png

tbscope
31st August 2010, 12:13
Most media formats are NOT free.
If you have OpenSuse for example, NON of these (the non free ones I mean) will play, even with everything correctly installed.

You just miss the necessary codecs.
On how to install those, check google, or your distro help channels.

hakermania
31st August 2010, 12:21
Sorry, nut you are wrong. I've installed the correct codecs. All of my other players do play MP3
http://a.imageshack.us/img411/352/screenshot1fmx.png

Talei
31st August 2010, 12:25
Think that hakermania and me have Unix as i can see from his logo...

From my experience Phonon works better on "Unix" then on Windows. I wrote player that streams video from the site (audio/video) and it works perfect on Linux, on Windows there is nightmare with DS codec.

I tested example with:

Distributor ID: Ubuntu
Description: Ubuntu 10.04.1 LTS
Release: 10.04
Codename: lucid

Qt 4.6.3
and

Distributor ID: Debian
Description: Debian GNU/Linux testing (squeeze)
Release: testing
Codename: squeeze

Qt 4.6.2
As tbscope said some codecs are "close source" and thus not included in "Unix" by default. AFAIK there is no way to play wmav2 (vma8) on NIX, but I can be wrong on this one. Rest is probably in "bad" or "ugly" package.

hakermania
31st August 2010, 12:27
But as i said (see screenshot) I've install the codecs.....

Talei
31st August 2010, 12:33
hakermania try:

gstreamer0.10-ffmpeg
gstreamer0.10-fluendo-mp3
gstreamer0.10-plugins-ugly
Those (ugly) are so called restricted format, that's why they are not included by default.

hakermania
31st August 2010, 12:44
All already installed
http://a.imageshack.us/img829/2865/screenshot2ho.png


http://a.imageshack.us/img291/5836/screenshot3wi.png


http://a.imageshack.us/img409/8393/screenshot4s.png

Talei
31st August 2010, 12:47
I installed these and everything works fine for me, so problem is with Your codec/system. You probably should ask question in Ubuntu forum about this.

Bong.Da.City
31st August 2010, 12:59
Same problem here... I finally managed tto install phonon and compile the application... Thanks to hakermania.. Anyway it doesn't play mp3 files.. I also have those packets you mentioned before....

gstreamer0.10-ffmpeg
gstreamer0.10-fluendo-mp3
gstreamer0.10-plugins-ugly

wysota
31st August 2010, 14:59
Can you play those mp3 files using pure gstreamer? Please also note that Phonon requires particular version of gstreamer (as mentioned in the docs).

hakermania
31st August 2010, 15:36
Yeah. I can listen to mp3 files through pure gstremer. So, Phonon has a lot of dependencies as I understood. This means that it is not so useful because users that will use my app would have to download and install all these packages in order to Phonon to work, right?... How about using QAudioOutput? What does it support?
http://a.imageshack.us/img64/6616/screenshot1rg.png

wysota
31st August 2010, 19:05
If you install phonon, your package manager should install all dependencies as well. Actually I'm using xine backend for phonon on my Linux box and not gstreamer. I only had to install phonon-gstreamer and phonon-xine packages for both backends.

hakermania
1st September 2010, 15:24
Thanks, but my package manager cannot find the files you specified. Also, what about QAudioOutput ? Can I play music with this?

hakermania
1st September 2010, 15:48
I found a code and tranformed it (hehe) to this:

#include <QFile>
#include <QAudioFormat>
#include <QAudioOutput>
#include <QSound>

int main()
{
QFile inputFile;
inputFile.setFileName("/home/alex/Music/noh.wav");
inputFile.open(QIODevice::ReadOnly);

QAudioFormat format;
format.setFrequency(8000);
format.setChannels(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
QAudioOutput *audio = new QAudioOutput( format, 0);
audio->start(&inputFile);
return 0;
}

but the only output is
QObject::startTimer: QTimer can only be used with threads started with QThread and no sound is heard.. (--_--)

wysota
1st September 2010, 15:59
Well, obviously this won't work, especially if you exit the application immediately. Query your package manager for phonon and install everything related to it. You should at least get playback for the free formats (like ogg). Test it with the mediaplayer Qt example.

hakermania
1st September 2010, 17:15
Thank you. I installed Phonon and I tried the MediaPlayer example. unfortunately, even after the installation of all the codecs I can't still play mp3 files. This is quite embarrassing because there are some apps that support mp3 file playing, like Alarm Clock from the Software package manager in ubuntu... I downloaded the source but I didn't understand how does it do it haha.... anyway.... Is there any other other way to play mp3 files?

wysota
1st September 2010, 17:30
unfortunately, even after the installation of all the codecs I can't still play mp3 files
Can you play ogg files? Or any other kinds of files?

hakermania
1st September 2010, 19:01
Yes. i can play ogg and wav files. But I cannot play mp3 at all. All mp3 codecs need have been installed. We spoke about phonon and codecs that should be installed in this thread at post No#10 - post No#18
So, as Bong.Da.City has the same problem with me, I don't believe that there is a problem with the system codecs, as the necessary codecs have been installed. :/
If there is no solution on how to play mp3 files with phonon, I would like at least to know how to make the code that I posted above work and I'll use canberra-gtk-play (see post No#1 in this thread) as it supports wav and ogg files as well, so there is no point using phonon libraries as i have already include stdlib.h and i can call system() to play the sound.... :(:crying::crying:

wysota
1st September 2010, 19:53
All mp3 codecs need have been installed.
Apparently not.


We spoke about phonon and codecs that should be installed in this thread at post No#10 - post No#18
Run the phonon/capabilities example and see the list of supported file types.

So, as Bong.Da.City has the same problem with me, I don't believe that there is a problem with the system codecs, as the necessary codecs have been installed. :/


If there is no solution on how to play mp3 files with phonon, I would like at least to know how to make the code that I posted above work and I'll use canberra-gtk-play (see post No#1 in this thread) as it supports wav and ogg files as well, so there is no point using phonon libraries as i have already include stdlib.h and i can call system() to play the sound.... :(:crying::crying:
Bearing the fact that canberra-gtk-play probably uses gstreamer, the same as phonon that uses gstreamer, I don't really see the point of doing that. Phonon has nothing to do with the fact whether you can or cannot play mp3 files. If you can play anything then phonon works fine. Its work ends with passing the stream of bytes to gstreamer. By the way, you can also try the xine phonon backend from kde, maybe it'll work better for you. Also check if you can play the mp3 with totem as it has gstreamer as its backend too.

hakermania
1st September 2010, 22:00
I can play mp3 files with totem:
http://a.imageshack.us/img830/5578/screenshot3nb.png
Although mp3 is not included in the list of files listed after the compilation of phonon/capabilities:

--ALSA--
annodex
x-annodex
aiff
x-aiff
x-pn-aiff
flac
x-flac
x-realaudio
basic
x-basic
x-pn-au
x-mod
mod
it
x-it
x-stm
x-s2m
s3m
med
x-amf
x-xm
xm
x-ogg
ogg
mp4
x-8svx
8svx
168sv
x-ms-wma
x-pn-realaudio
x-pn-realaudio-plugin
x-real-audio
x-wav
wav
x-pn-wav
x-pn-windows-acm
musepack
x-musepack
x-wavpack
x-flac
flac
x-vorbis+ogg
What should I do:confused::confused:

wysota
2nd September 2010, 00:48
Did you try the xine backend? Also make sure you have ffmpeg and ffmpeg support for gstreamer installed if you are willing to continue with the gstreamer backend (provided you indeed have gstreamer as the backend). By the way, your list is very poor, mine is much richer.

Talei
2nd September 2010, 02:42
There is also vlc and mplayer backeds, see:
http://www.gitorious.org/phonon
http://code.google.com/p/phonon-vlc-mplayer/

And maybe try running LiveCD Ubuntu (I assume, from the screens, that it's your Linux flavour) and mount partition with compiled examples and try installing there missing codec. It's just a thought but maybe You have broken dependences in Your system or "something strange" is going on. Test with native "Movie Player".
As said before, I installed (before posting) mentioned codec package in my Ubuntu and everything worked fine, same goes for Debian (although I had codec installed... well a long time ago).

hakermania
2nd September 2010, 09:12
There's nothing strange with my system. Bong.Da.City (I hope he'll post again because I need support here haha) has the same problem. Two same situations with the same problem in the same thread? I don't believe into such coincidences...Our systems haven't got any problem.
@wysota I installed them. MP3 still can't be played.
@Talei, I got errors when trying to install both phnon-vlc and phonon-mplayer when doing cmake..The output is:
VLC:

alex@MaD-pc:~/phonon/phonon-vlc$ cmake vlc
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:45 (automoc4):
Unknown CMake command "automoc4".


CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 2.8)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
alex@MaD-pc:~/phonon/phonon-vlc$

MPlayer:

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at libmplayer/CMakeLists.txt:15 (qt4_wrap_cpp):
Unknown CMake command "qt4_wrap_cpp".


CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 2.8)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
alex@MaD-pc:~/phonon/phonon-mplayer$

Thx again.

wysota
2nd September 2010, 12:55
There's nothing strange with my system. Bong.Da.City (I hope he'll post again because I need support here haha) has the same problem.
You don't know he has the same problem. He has a similar problem. The reason might be completely different.


@wysota I installed them. MP3 still can't be played.
"Installing" is not enough. You have to make sure Phonon actually uses the other backend (you can temporarily move the gstreamer backend files elsewhere).


Let's get one thing straight and I hope all people who are having problems with Phonon will read it very carefully and make sure they understand it.

To make Phonon work, three things have to happen simoultaneously:
1. Phonon library has to be compiled and installed together with all its dependencies. On Linux this is called libphonon.so and is usually located in /usr/lib (if installed for KDE) and/or $QTDIR/lib when installed by compiling Qt. On Windows this is phonon4.dll and probably resides in $QTDIR/bin. The library is responsible for providing an adapter between your code and phonon backend.

2. Phonon backend has to be compiled and installed together with all its dependencies. On Linux this is called libphonon_<X>.so where <X> can be one of {gstreamer,xine,vlc,mplayer} or possibly something else if a new backend is developed. The backend is located in /usr/lib/kde4/plugins/phonon_backend when installed for KDE and $QTDIR/plugins/phonon_backend when installed for Qt. On Windows this is called phonon_ds94.dll and is located in $QTDIR/plugins/phonon_backend. The backend is responsible for talking to the platform-dependent solution for playing multimedia such as gstreamer(0.10+) or xine on Linux, Direct Show on Windows and (AFAIR) Quick Time on MacOSX. The plugin has to be deployed with your application to the phonon_backend subdirectory to be able to play multimedia on target machines (unless you know there is a working phonon installation there, i.e. when using rpm and making sure KDE's Phonon is a dependency of your app).

3. Proper codecs, support files, etc. should be available for the solution used by Phonon backend.

On Unix...
...it is best to have ffmpeg installed which gives you access to /usr/lib/libavcodec and /isr/lib/libavformat. You can run ffmpeg -codecs to see available codecs built into the library. On different installations the list of codecs may be different as most Linux distros only enable so called Free (as in 'freedom of speech') codecs so i.e. flac might not be available. You can often install this library from a 3rd party vendor or non-free (as in 'freedom of speech') package source with additional (non-free) codecs enabled. But this might not enough to make media play in your apps. You often need to bind the codecs with the solution used by phonon backend:

For gstreamer you need to have gstreamer plugins installed (on my system (mdv) they are "gstreamer-plugins-base", "gstreamer-plugins-good", "gstreamer-plugins-bad" and "gstreamer-plugins-ugly" and also "gstreamer-ffmpeg" and a couple of others).
AFAIK Xine, MPlayer and VLC don't need any extra plugins, they will automatically pick up what's available on your system.

You can also install so called ''Windows codecs' which usually reside in /usr/lib/codecs or /usr/lib/win32 or in a similar location to get other proprietiary formats working. Getting ogg/ogv support might also be important (libvorbis/libtheora).

Also note that some codecs may require additional libraries, i.e. libflac

On Windows...
... you can install ffdshow which is the ffmpeg codec pack for Windows. The general rule is that whatever plays in Windows Media Player should play through Phonon too. The exception may be DRM-ed content, I don't know if that works.

You don't have much influence whether a particular file will play on some target system as you don't know if particular codecs are installed. Deploying them yourself is probably not a good idea (they might conflict with what the user already has in his system) so it's a better idea to use codecs and formats that are available by default in the target system. It is usually PCM (wav) for audio and mpeg-2 for video. It is not mp3 nor xvid/divx/mkv.

Troubleshooting

General rule #1: If anything (wav/ogg/mpeg-2) plays, then Phonon is installed correctly and items #1 and #2 from the above list are fulfilled. You are either missing codecs or plugins for your platform's multimedia solution. Unless you are sure a particular 3rd party player uses the same soolution for playback, testing the offending file with the player won't give you any meaningful results. Use the Phonon::BackendCapabilities class to see what should work with your current settings.

General rule #2: If you can't compile Phonon-based application or you can't execute it then you probably have problems with the (lib)phonon library (#1 from the above list). Check dependencies (ldd/dependency walker).

General rule #3: If you can't compile Phonon-based applications but Phonon examples can be executed correctly (regardless whether you get playback or not) then Phonon library is installed correctly but you are missing development files for Phonon (headers or import libraries).

General rule #4: Phonon can't be compiled statically into your application and in general Phonon will not work for statically built apps. Link your Phonon-based app dynamically.

General rule #5: If Phonon-based app compiles and runs but doesn't play any files (wav/ogg/mpeg-2) the problem is with the backend. Check if you have a backend installed (#2), verify its dependencies (ldd/dependency walker). You may try a different backend to see if it makes a difference. Use Phonon::BackendCapabilities to see what's available in your current settings. Sometimes it is good to rename phonon_backend directory to something else to see if Phonon starts complaining about no backend being available. Sometimes the backend may be taken from a different location than you expect. Same goes for the Phonon library. A useful tool for checking the backend is the KDE's system-settings application - go to its multimedia section to see what backends are available and which is the active one.

General rule #6: Phonon is not responsible for playback of multimedia files. It is responsible for talking with your platform's solution. If a particular file doesn't work, don't blame Phonon.

General rule #7: Check stupid mistakes such as permission problems (files, devices, resources) and spelling.

hakermania
2nd September 2010, 14:18
I installed libavformat and libacodec libraries and now mp3s can be played by the Phonon Music Player. The thing is, what dependencies have to include in my program in order to work in other PCs?

wysota
2nd September 2010, 14:22
See the last paragraph of my post before the "troubleshooting" section.

hakermania
2nd September 2010, 14:53
Apf.. Too complicated.. Too hard! Check the backends, install the dependencies...And all these only for mp3 playing. Useless. I think I'll use the pre-installed canbera-gtk-play and have only ogg and wav support

wysota
2nd September 2010, 16:05
I think I'll use the pre-installed canbera-gtk-play and have only ogg and wav support
I guess your app wouldn't work on my system then :)

By the way, I've placed the how-to in the wiki: How to get Phonon working

hakermania
2nd September 2010, 21:21
My app wouldn't work in your system because it uses a lot of other bash commands like sed and other because this way is much easier than the C++ way (I mean for file processing). In order to play mp3 files, I found a terminal command called mpg123 :) only 35KB ;)

wysota
2nd September 2010, 21:25
But I do have sed installed on my system, so that's perfectly fine. I don't have your gtk player installed. I think I don't have mpg123 installed too, after all I have mplayer...

Edit: I do have mpg123. You should add another 250kB to your mpg123 as it requires the mpg123 library :) Dependencies, dependencies, dependencies...