MciSendString does not pause audio from a stream

I recently asked for a solution similar to these questions:

Is there a way to pause / stop the mp3 file playing with mcisendstring with the “wait” option?

I want to implement a function in my audio player that allows people to continuously play sound, and the slider moves in accordance with the current second in which the track works, and also with the ability to go to the next track after the current track has ended

After (as you can read in the link), trying to do this with

mciSendString("play mp3 wait", NULL, 0, NULL);

which failed due to the problem that the track cannot be paused or stopped before it is completed, now I am trying to implement it differently. Currently, when I start playing on a track, I also start another thread that starts the counter. The counter receives the track length in seconds and counts the time, also offering a mutex to pause / resume the counter. To stop my MusicCycle from a simple loop without control, I join the stream, so I wait for it to complete.

void Music::MusicCycle(std::wstring trackPath)
{
    while (true)
    {
        OpenMP3(trackPath);
        mciSendString("play mp3", NULL, 0, NULL);

        m_counterThread = boost::thread(boost::bind(&Counter::StartCount, m_counter, <length of track in seconds>));
        m_counterThread.join();

        //... Get new track here
    }
}

Note that this entire method is also created in the stream:

m_cycleThread = boost::thread(boost::bind(&Music::MusicCycle, this, trackPath));

The stream starting with the MusicCycle function is as follows:

void Counter::StartCount(int seconds)
{
    boost::mutex::scoped_lock lock(m_mutex);

    for (int i = 0; i < seconds; i++)
    {
        while (m_counterLock)
        {
            m_condVar.wait(lock);
        }

        boost::this_thread::sleep(boost::posix_time::seconds(1));
    }
}

In addition, I added another mutex lock / unlock functionality here with my Pause / Resume methods, which also call the corresponding mciSendString functions

mciSendString("resume mp3", NULL, 0, NULL);

mciSendString("pause mp3", NULL, 0, NULL);

, mciSendString , , .

, - . , wait mciSendString

?

EDIT: , - . # , Invokes . , ?

EDIT2: , , PostMessage WinAPI. ? , - ? , .

- ++?

+4
1

EDIT: , - . # , Invokes .

. Ifff , - (, # ( Java ..) Invoke-on-UI-thread). .

EDIT2: , , PostMessage WinAPI. ? , - ? , .

- ++?

, , -/, . ++ "" GUI , , , .

Boost Asio . GUI, (Qt, MFC ..).

, , Win32 GUI , , . , .

. () , . pronto: , .


¹ , https://github.com/ocornut/imgui

² , , ,

+5

Source: https://habr.com/ru/post/1624172/


All Articles