FreeStreamer icon indicating copy to clipboard operation
FreeStreamer copied to clipboard

Wrong state callback when paused immediately after playing

Open IvanChan opened this issue 7 years ago • 4 comments

When state changed to PLAYING, pause immediately, after a while, PLAYING state comes! audio is not really playing actually.

Blame code below, I just can NOT figure it out why this timer is needed? I try to comment these, works well.

        if (THIS->m_state != PLAYING && !THIS->m_stateSetTimer) {
            // Set the playing state in the main thread

            CFRunLoopTimerContext ctx = {0, THIS, NULL, NULL, NULL};
            
            THIS->m_stateSetTimer = CFRunLoopTimerCreate(NULL, 0, 0, 0, 0,
                                                         stateSetTimerCallback,
                                                         &ctx);
            
            CFRunLoopAddTimer(THIS->m_mainRunLoop, THIS->m_stateSetTimer, kCFRunLoopCommonModes);
        }

IvanChan avatar Mar 03 '17 02:03 IvanChan

Notifications should come from the main thread and the easiest way for this is to use a runloop timer. If you mix the main thread and other threads, you are making difficult to spot crashes because the de facto Cocoa convention is that notifications come 99% of the cases from the main thread. So this works well may work for you 95% time and then for 5% time you get a bunch of weird crashes without proper synchronisation.

muhku avatar Mar 13 '17 15:03 muhku

void Audio_Stream::audioQueueStateChanged(Audio_Queue::State state)

this callback always notify PLAYING state for now, so I think the timer might be duplicated.

If there is a problem, @muhku how to fix this problem below?

When state changed to PLAYING, pause immediately, after a while, PLAYING state comes! audio is not really playing actually.

IvanChan avatar Mar 14 '17 02:03 IvanChan

Have this problem too, when the player state is buffering, pause/stop is not working. Did you resolve this problem? @IvanChan

somebear avatar May 03 '17 10:05 somebear

same problem

satishVekariya avatar Mar 12 '20 07:03 satishVekariya