Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]sf::Music "PLUGIN" not working and exits without playing the audio  (Read 16040 times)

0 Members and 1 Guest are viewing this topic.

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
So I was trying to implement mp3 support to my audio player and I tried HeinC's mp3 reader from the SMFL Wiki: https://github.com/SFML/SFML/wiki/Source%3A-Mp3-Soundfile-Reader



But it spits this out and exits by itself.

Quote
START: C:/Users/shale/Music/Airpod_Shotty.mp3
CHECK: can Mp3 Reader handle the stream?
created handle at address 14352496
opened handle for feeding
first header decoded
buffersize: 2048
total bytes read: 2048
total bytes decoded: 0
reads from stream: 1
CHECK: SUCCESS
Mp3 reader close
OPEN
created handle at address 14352496
opened handle for feeding
first header decoded
buffersize: 2048
total bytes read: 2048
total bytes decoded: 0
reads from stream: 1
format: sample rate in Hz: 44100
format: channels: 2
format: encoding: 208
header: MPEG version: 1.0
header: MPEG Audio mode: Joint Stereo (2 channels)
header: Mode type of variable bitrate (vbr): Variable Bitrate Mode
header: MPEG Audio Layer (MP1/MP2/MP3): 3
header: Mode extension bit flag: 2
header: Emphasis type (?): 0
header: Target average bitrate: 0
header: Bitrate of the frame (kbps): 192
header: Sampling rate in Hz: 44100
header: Size of the frame (in bytes, including header): 626
wrote info: channels: 2, expected number of samples: 311, sampling rate: 44100
OPEN: SUCCESS
Resource not found
READ: request up to 88200 samples. size of streambuffer: 80000 bytes
decoded 4796 bytes from leftover input. offset into samples: 4796 / 176400
read 80000 bytes from stream
decoded 80000 to 171604 decoded bytes. total decoded bytes: 176400 / 176400
samples delivered: 88200 of 88200 requested
total bytes read: 80000
READ: SUCCESS
SEEK sample offset 0 FIXME not implemented
Mp3 reader close

this is my main.cpp

Quote
#include "SoundFileReaderMp3.hpp"
#include <SFML/Audio.hpp>

#include <iostream>
#include <string>

int main(int argc, const char* argv[]) {
   
   if(argc == 1) {
      std::cout << ": missing argument <absolute filename>" << std::endl;
      return -1;
   }

   std::string filename(argv[1]);

   std::cout << "START: " << filename << std::endl;
   
   sf::SoundFileFactory::registerReader<audio::SoundFileReaderMp3>();

   sf::Music music;

   if (!music.openFromFile(filename)) {
      std::cout << "check your file path. also only wav, flac, ogg and mp3 are supported." << std::endl;
      return -1;
   }

   music.play();

   while(music.getStatus() != sf::SoundSource::Status::Stopped)
   {}

   return 0;
}
« Last Edit: May 09, 2021, 12:25:12 am by Ragbot »

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #1 on: April 25, 2021, 03:43:57 pm »
Yeah so I also tried to check with the example HeinC Provided but that too just played for 1s and then crashed.
So now I have no idea what to do.
Any help guys?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #2 on: April 26, 2021, 08:28:23 am »
Quote
But it spits this out
And "this" is? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #3 on: April 27, 2021, 07:51:27 pm »
I fixed the question sryyyyy I forgot to paste in the output  :-[ :-[

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #4 on: April 28, 2021, 12:16:41 am »
The code on the wiki doesn't seem to implement the seek function, so maybe the reading position remains at the end and is not reset to the start, thus nothing is played.

Either way, I suggest to run it through your debugger and see how or if the sound buffer is being filled.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #5 on: April 28, 2021, 09:05:29 am »
Um... Sorry but I don't know how to "Debug" but I did try starting it on the VS Code Debbuger but the music "variable" was "{...}" and the sound buffer? um, it's not there...
« Last Edit: April 28, 2021, 09:13:28 am by Ragbot »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #6 on: April 28, 2021, 09:26:11 am »
There are a lot of resources out there to learn how to use your tool.
It's essential to learn your tools. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #7 on: April 28, 2021, 10:20:45 am »
Oh hey, I just found out about breakpoints now I can just add breakpoints wherever I want to check... but. I don't know much about the "seek()" you mentioned there so um could you abbreviate on that like is it a function? or is it something related to the audio reader? like what does it do?

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #8 on: April 28, 2021, 06:34:52 pm »
I just saw this on the seek function

Quote
src/SoundFileReaderMp3: 226:6:
        // probably should go something like this
   // off_t ok = mpg123_feedseek (m_handle, sampleOffset, SEEK_SET, NULL);

is this what you mentioned about

Quote
The code on the wiki doesn't seem to implement the seek function, so maybe the reading position remains at the end and is not reset to the start, thus nothing is played.

I tried uncommenting it but it still didn't work so what should have I done there? also
you mentioned the seek function wasn't implemented on the wiki so was it implemented elsewhere?

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #9 on: May 08, 2021, 11:39:06 am »
Is there any help I can get with this... :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #10 on: May 08, 2021, 04:32:39 pm »
I didn't really like the LGPL license of mpg123, so I took lieff's example implementation for SFML and extracted it into a standalone version.

https://github.com/SFML/SFML/wiki/Source%3A-Mp3-Soundfile-Reader-minimp3

All you need to do is grab the header and source file and the two minimp3 headers and you're good to go ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ragbot

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: sf::Music "PLUGIN" not working and exits without playing the audio
« Reply #11 on: May 09, 2021, 12:23:38 am »
Thanks! that worked beautifully well!