Why doesn't Bass_ChannelStop() reset the progress to 0?

Started by kksskkoopp, 7 Mar '25 - 13:18

kksskkoopp

Hi everyone, I'm new here and I have a question: Why doesn't Bass_ChannelStop() reset the progress to 0? When I Bass_ChannelStop() the music and then Bass_ChannelPlay() it again, it continues from where it stopped, instead of playing from the beginning as I expect. Bass_ChannelStop() seems to function the same as Bass_ChannelPause(), so what is the difference between them? ???


Here is my code and output:
#include <iostream>
#include <string>
#include <thread>
#include "bass.h"


using namespace std;


int main()
{
 string music_path = "E:/Desktop/MISC/music/BABYMONSTER - DRIP.mp3";
    HSTREAM stream = 0;


 if (!BASS_Init(-1, 44100, 0, nullptr, nullptr))
 {
  cerr << "bass init failed" <<  endl;
  return 0;
 }
    cout << "bass init success" << endl;


    if (stream) {
        cout << "stream is not empty" <<  endl;
        BASS_StreamFree(stream);
    }
    else
    {
        cout << "stream is empty" <<  endl;
    }


    stream = BASS_StreamCreateFile(FALSE, music_path.c_str(), 0, 0, 0);
    if (!stream) {
        cerr << "load failed" <<  endl;
    }
    else {
        cout << "load success: [" << music_path << "]" << endl << endl;
    }



 if (BASS_ChannelPlay(stream, FALSE)) {
  cout << "play success" <<  endl;
 }
 else {
   cerr << "play failed" <<  endl;
 }


 this_thread::sleep_for(chrono::seconds(1));


    switch (BASS_ChannelIsActive(stream)) {
        case BASS_ACTIVE_PLAYING: cout << "BASS_ACTIVE_PLAYING" << endl;  break;
        case BASS_ACTIVE_PAUSED:  cout << "BASS_ACTIVE_PAUSED"  << endl;  break;
        case BASS_ACTIVE_STOPPED: cout << "BASS_ACTIVE_STOPPED" << endl;  break;
    }
    cout << "progress: " << BASS_ChannelGetPosition(stream, BASS_POS_BYTE) << "/" << BASS_ChannelGetLength(stream, BASS_POS_BYTE) << endl << endl;


    this_thread::sleep_for(chrono::seconds(5));


    int flag = 2;
    if (flag == 1)
    {
        if (BASS_ChannelPause(stream)) {
            cout << "paused success" << endl;
        }
        else {
            cerr << "paused failed" << endl;
        }
    }
 else
 {
        if (BASS_ChannelStop(stream)) {
            cout << "stopped success" << endl;
        }
        else {
            cerr << "stopped failed" << endl;
        }
 }



    switch (BASS_ChannelIsActive(stream)) {
        case BASS_ACTIVE_PLAYING: cout << "BASS_ACTIVE_PLAYING" << endl;  break;
        case BASS_ACTIVE_PAUSED:  cout << "BASS_ACTIVE_PAUSED" << endl;  break;
        case BASS_ACTIVE_STOPPED: cout << "BASS_ACTIVE_STOPPED" << endl;  break;
    }
    cout << "progress: " << BASS_ChannelGetPosition(stream, BASS_POS_BYTE) << "/" << BASS_ChannelGetLength(stream, BASS_POS_BYTE) << endl << endl;


    this_thread::sleep_for(chrono::milliseconds(100));


    if (BASS_ChannelPlay(stream, FALSE)) {
        cout << "play success" << endl;
    }
    else {
        cerr << "play failed." << endl;
    }


    switch (BASS_ChannelIsActive(stream)) {
    case BASS_ACTIVE_PLAYING: cout << "BASS_ACTIVE_PLAYING" << endl;  break;
    case BASS_ACTIVE_PAUSED:  cout << "BASS_ACTIVE_PAUSED" << endl;  break;
    case BASS_ACTIVE_STOPPED: cout << "BASS_ACTIVE_STOPPED" << endl;  break;
    }
    cout << "progress: " << BASS_ChannelGetPosition(stream, BASS_POS_BYTE) << "/" << BASS_ChannelGetLength(stream, BASS_POS_BYTE) << endl << endl;



    this_thread::sleep_for(chrono::seconds(5));


 cout << "EXIT" << endl;



    return 0;
}


Here is the output:
bass init success
stream is empty
load success: [E:/Desktop/MISC/music/BABYMONSTER - DRIP.mp3]


play success
BASS_ACTIVE_PLAYING
progress: 173064/31901220


stopped success
BASS_ACTIVE_STOPPED
progress: 1055632/31901220


play success
BASS_ACTIVE_PLAYING
progress: 1062808/31901220


EXIT

Ian @ un4seen

BASS_ChannelStop is indeed a lot like BASS_ChannelPause. The main difference is that auto-freeing (the BASS_STREAM_AUTOFREE flag) applies to BASS_ChannelStop but not BASS_ChannelPause. In both cases you can have playback resume from the start by setting restart=true in the BASS_ChannelPlay call, or calling BASS_ChannelSetPosition with pos=0 first.