Created
June 16, 2017 02:07
-
-
Save jamiltron/ada86682674717ab0bd9e0f2f90343dc to your computer and use it in GitHub Desktop.
Ogg file causes SFML-Audio 2.4.2 to hang forever.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Audio.hpp> | |
#include <SFML/System.hpp> | |
#include <memory> | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
class MyStream: public sf::InputStream | |
{ | |
public: | |
MyStream(std::string const& uri); | |
sf::Int64 read(void* data, sf::Int64 size) override; | |
sf::Int64 seek(sf::Int64 position) override; | |
sf::Int64 tell() override; | |
sf::Int64 getSize() override; | |
private: | |
std::ifstream _stream; | |
sf::Int64 _size; | |
}; | |
MyStream::MyStream(std::string const& path) | |
: _stream(path, std::ios::in | std::ios::binary) | |
{ | |
_stream.seekg(0, std::ios_base::end); | |
_size = tell(); | |
seek(0); | |
} | |
sf::Int64 MyStream::read(void* data, sf::Int64 size) | |
{ | |
_stream.read((char *)data, size); | |
return _stream.gcount(); | |
} | |
sf::Int64 MyStream::seek(sf::Int64 position) | |
{ | |
_stream.clear(); | |
_stream.seekg(position, std::ios_base::beg); | |
return tell(); | |
} | |
sf::Int64 MyStream::tell() | |
{ | |
return _stream.tellg(); | |
} | |
sf::Int64 MyStream::getSize() | |
{ | |
return _size; | |
} | |
int main(void) | |
{ | |
std::string str = "./hangs_forever.ogg"; | |
std::cout << "creating stream from " << str << std::endl; | |
MyStream stream{ str }; | |
sf::Music music; | |
std::cout << "opening from stream" << std::endl; | |
music.openFromStream(stream); | |
std::cout << "playing..." << std::endl; | |
music.play(); | |
while (music.getStatus() == sf::SoundSource::Playing) | |
; | |
std::cout << "done playing " << str << "\n" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment