Nana C++ Library  
An open-source C++ framework project
The Nana Programmer's Guide 
nana::audio::player

Description

A class for playing an audio file.

Model of

None

Public base classes

None

Supported Formats

PCM Windows WAV


Members

player() The default construction.
player(const nana::string&) Opens an audio file.
~player() The destruction
bool open(const nana::string&) Opens an audio file.
void play() Play the audio.
void close() Close the openned audio.



File

nana/audio/player.hpp

Notes

1, Play an audio file.

#include <nana/audio/player.hpp>

int main()
{
    nana::audio::player player(STR("./audio.wav"));
   
    player.play();  //Play the audio, it waits until the audio is finished.
}


2, Play an audio file asynchronously. Play the audio when a button is clicked, and it does not block the UI thread.

#include <nana/gui/wvl.hpp>
#include <nana/gui/widgets/buttton.hpp>
#include <nana/audio/player.hpp>
#include <nana/threads/pool.hpp>

int main()
{
    nana::audio::player player(STR("./audio.wav"));
    nana::threads::pool pool(1); //Only 1 thread.

    using namespace nana::gui;

    form fm;
    button btn(fm, nana::rectangle(10, 10, 100, 24));
    btn.caption(STR("Play the audio"));

    //C++03
    btn.make_event<events::click>(pool_push(pool, nana::make_fun(player, &nana::audio::player::play)));


    //C++11
    btn.make_event<events::click>(pool_push(pool, [&]()
                           {
                               player.play();
                           }));


    fm.show();

    exec();
}




Move to The Nana Programmer's Guide Main Page