您好,我想用 super 功能的SDK创建一个播放器,但是我无法退出循环。歌曲结束后,他又开始播放了,因为删除了吗?


void SuperpoweredExample::onPlayPause(bool play) {
pthread_mutex_lock(&mutex);
if (!play) {
    playerA->pause();
    playerB->pause();
} else {
    bool masterIsA = (crossValue <= 0.5f);
    playerA->play(!masterIsA);
    playerB->play(masterIsA);
};
pthread_mutex_unlock(&mutex);
}


public void SuperpoweredExample_PlayPause(View button) {  // Play/pause.
    playing = !playing;
    onPlayPause(playing);
    Button b = (Button) findViewById(R.id.playPause);
    b.setText(playing ? "Pause" : "Play");
}


SuperpoweredAdvancedAudioPlayer *playerA = *((SuperpoweredAdvancedAudioPlayer **)clientData);
    playerA->setBpm(126.0f);
    playerA->setFirstBeatMs(1);
    playerA->setPosition(playerA->firstBeatMs, false, false);
    playerA->exitLoop(); // not work
    playerA->looping = false; // not work
    playerA->togglePlayback();

    playerA = new SuperpoweredAdvancedAudioPlayer(&playerA , playerEventCallbackA, samplerate, 0);
    playerA->open(path, params[0], params[1]);

最佳答案

在您的方法playerEventCallbackA中处理播放状态

playerA = new SuperpoweredAdvancedAudioPlayer(&playerA , playerEventCallbackA, samplerate, 0);

这是主要玩家事件的回调。
如果您查看SuperpoweredAdvancedAudioPlayer.h类,您会发现
typedef enum SuperpoweredAdvancedAudioPlayerEvent {
    SuperpoweredAdvancedAudioPlayerEvent_LoadSuccess,
    SuperpoweredAdvancedAudioPlayerEvent_LoadError,
    SuperpoweredAdvancedAudioPlayerEvent_EOF,
    SuperpoweredAdvancedAudioPlayerEvent_JogParameter,
    SuperpoweredAdvancedAudioPlayerEvent_DurationChanged,
} SuperpoweredAdvancedAudioPlayerEvent;

而且,当您收到SuperpoweredAdvancedAudioPlayerEvent_EOF事件时,可以暂停播放或执行任何您想播放的操作。

例如。
    static void playerEventCallbackA(void *clientData, SuperpoweredAdvancedAudioPlayerEvent event, void *value) {
        SuperpoweredAdvancedAudioPlayer *playerA = *((SuperpoweredAdvancedAudioPlayer **)clientData);
        if (event == SuperpoweredAdvancedAudioPlayerEvent_LoadSuccess) {
            // handle player prepared
        } else if (event == SuperpoweredAdvancedAudioPlayerEvent_LoadError) {
            // handle error with player
        } else if (event == SuperpoweredAdvancedAudioPlayerEvent_EOF && !loopingA) {
            playerA->pause();
        }
    }

希望能帮助到你。

10-06 09:09