Problems setting the position in a stream

Started by Luckie,

Luckie

Hello there,
I just discovered BASS and up to now I'm very satisfied. But I'm having quite a problem now.

I'm programming a small MP3-Player. Playing a filestream works fine. I can even display the position using a trackbar. But if I try to change the position using the slider it does not work properly. Instead continue playing at the desired position it gets back to the start and starts playing from the begining.

Here is my code:
void StrTimerProc() {
  QWORD TrackPos;
  TrackPos = BASS_ChannelGetPosition(hFileStream);
  if (TrackPos == -1) {
    BASSError("Position in der Datei konnte nicht ermittelt werden.");
    KillTimer(hApp, IDC_STRTIMER);
  }
  SendDlgItemMessage(hApp, IDC_TRACKER, TBM_SETPOS, (LPARAM)TRUE, (WPARAM)TrackPos / 100);
  if (TrackPos == BASS_StreamGetLength(hFileStream))
    KillTimer(hApp, IDC_STRTIMER);
}

void StrSetPos(QWORD NewPos) {
  if (!BASS_ChannelSetPosition(hFileStream, NewPos))
    BASSError("Position konnte nicht gesetzt werden.");
}

int StrPlay() {

  QWORD StreamLength;

  hFileStream = BASS_StreamCreateFile(FALSE, szFilename, 0, 0, BASS_STREAM_AUTOFREE);
  if (hFileStream == 0) {
            BASSError("Datei-Stream konnte nicht erzeugt werden");
            return -1;
      }
  
  StreamLength = BASS_StreamGetLength(hFileStream) / 100;
  SendDlgItemMessage(hApp, IDC_TRACKER, TBM_SETRANGEMAX, (LPARAM)TRUE, (WPARAM)StreamLength);
  SendDlgItemMessage(hApp, IDC_TRACKER, TBM_SETTICFREQ, (WPARAM)StreamLength / 50, 0);

      BASS_Start();
      if (!BASS_StreamPlay(hFileStream, FALSE, 0)) {
            BASSError("Fehler beim Wiedergeben der Datei.");
            return -1;
      }
  SetTimer(hApp, IDC_STRTIMER, 10, (TIMERPROC)StrTimerProc);
      return 0;
}

And sliding the trackbar:
 case WM_HSCROLL:
    switch LOWORD(wParam) {
      case TB_THUMBTRACK:
          KillTimer(hDlg, IDC_STRTIMER);
          StrSetPos(SendDlgItemMessage(hDlg, IDC_TRACKER, TBM_GETPOS, 0, 0) / 100);
          SetTimer(hApp, IDC_STRTIMER, 10, (TIMERPROC)StrTimerProc);
        break;
    }
    return TRUE;
Don't mind the German error messages.

But now the strange thing about it. I already wrote a small program for testing purpos using Delphi and the VCL. If I use Delphi and the VCL I can set the position using a trackbar.

So what's wrong with my code? I would be glad if you could help me.

Irrational86

#1
QuoteAnd sliding the trackbar:
 case WM_HSCROLL:
     ...
          StrSetPos(SendDlgItemMessage(hDlg, IDC_TRACKER, TBM_GETPOS, 0, 0) / 100);
     ...
    return TRUE;
Do you see the / 100? Well replace it with * 100 and that should fix it..

Luckie

#2


Thanks a lot. I was nearly becoming insane.

Irrational86

#3
Small mistakes that happen ;)

:laugh: :laugh: Btw, I really like your little gif, can i keep a copy?

Luckie

#4
Next time I can't get to sleep at night time I better start Minesweeper instead start programing.

Well if you like that one you might like that one as well:

Irrational86

Hahaha, funny thing, i just msged you on ICQ, but you are not answering..