I want to play only one mp3 file in loop Qt - c++

I have only one mp3 file paying in background. I want that mp3 file to played till I close the application.
What I am facing is that the mp3 file is played for only once and then stops. I want it to be played again.
Find sample code below
Code:
QMediaPlayer *music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/bgsound.mp3"));
music->setVolume(20);
music->play();
Thanks in advance!!

Simply do it by connecting signals and slots as follows:
connect(music,&QMediaPlayer::mediaStatusChanged,music,&QMediaPlayer::play);

Related

WAV file with QML SoundEffect audio playback is distorted

My first go at using SoundEffect with QML, and I'm getting mixed results with no clear understanding of why. I can successfully use QML SoundEffect in user interface within an embedded C++ device. The thing I cannot solve is why some WAV files will play perfectly clear, and some will not.
I'm certain my code is correct...its something about how the audio is interpreted. I cannot share the WAV files I'm using...but here's what's happening:
I have two WAV files:
wav_file1_that_works.wav (which is 83kb)
and
wav_file2_that_does_not work.wav (which is 110kb)
Both of these files play just fine in VLC or Media Player or whatever. But when ran through the QML function to play as a feedback for touch on the device, the first WAV file plays just fine, while the second one does not. It does not appear to be a hardware issue as this same issue comes up exactly the same when working on virtual environment. I'm suspecting there is some limitation to using WAV audio within the QT/QML environment? But I cannot find any limits in the documentation. My only suspicion is the file size, or some other specific sound file requirement.
First I declare the sound link to the file:
SoundEffect {
id: playSound
source: "qrc:/wav_file2_that_does_not work.wav"
}
Then on the UI event it's played (not the exact code, but the event certainly works like this:
MyUiItem {
onMyUiTouched: {
playSound.play();
}
}
and file 1 plays perfectly, and file 2 plays, but with a very distorted scratchy sounds.
I probably don't know enough about how WAV file encoding works, but on the surface both files seems to be encoded correctly.
I solved this by refactoring how the app compiles as my WAV file was getting compressed. So unfortunately this was something I discovered that if I let my enterprise deployment system do its thing it compresses everything including all multi-media unless I apply certain parameters to not compress. And so now this works. Thanks for the help.

How to play background music in KaboomJS

I am making a game with the kaboom library and would like to add background music, i read the docs and found const music = play("music"); music.loop() but this seems to only play it once, the file is an MP3 file and i dont get any errors

libVLC creates two audio streams

I'm using libVLC to play a video file. If I use my code in as standalone video player, I am having no issues. The video plays very well. I can pause and play the video as I like.
When I use the same code, without modifications, in a plugin, and then play the same file, something unique happens: VLC creates two audio streams for the same video file. Now if I pause the video using libvlc_media_player_pause(...), it pauses the video and one audio stream. The other audio stream continues playing.
Any suggestions as to why this could be happening?
The application itself is written in Qt5. I have tested this issue with both audio and video files.
LibVLC version is 3.0.0
Header file and Source file are pastebin links
The mistake I did was in the code for plugin. Two instances of NBAVPlayer were created in the plugin code leading to two audio streams, one visible video stream and one hidden video stream. I have fixed the issue with the plugin, and now everything works properly.

Detect if video has no audio in C++, preferable using Qt Phonon

I am creating a video player if Phonon and Qt. everything is working fine, but when I have a video in my playlist that does not have audio I wish to play another audio.
how can I do that? I mean, how can I detect that the video has no audio?
EDIT: By no audio I meant "no audio channel"
Qt 5 might help you out. Check out Phonon::Gstreamer::MediaObject. The API is similar to the ordinary MediaObject, but with some additional functions. The one you want is audioAvailable().

video player with qt phonon (using python)

I am working on Windows xp and am trying to get a simple video player running.
I am trying to use Phonon::VideoPlayer module for this. I am connecting the signal as
connect(self.player,SIGNAL("finished()"),self.player.deleteLater)
and then , when the Play button is pressed, it makes the following call:
self.player.play(Phonon.MediaSource("C:\\vid.mp4"))
But, this doesn't display the video in the video player widget. Neither can I hear audio. Can anyone help??
I tried using different video file formats but no luck.
Try writing
self.player.play(Phonon.MediaSource("C:\\vid.mp4"))
to escape the \
Phonon::MediaSource mediaSource= Phonon::MediaSource("C:\\vid.mp4");
Try creating media sources like this and also other Phonon objects..