简体   繁体   中英

C++ BASS Library - simple mp3 sample playing

I have checked the BASS reference for a solution, but it was not to be found by me. My audio just does not want to play and yes, I checked if my speakers are working. Here is the "code":

#include "stdafx.h"
#include "D:\\Libraries\BASS\c\bass.h"
#include <iostream>
#include <cstdlib>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{   
    BASS_Init(-1, 44100, 0, 0, NULL);
    BASS_SetVolume(1);
    HSAMPLE sample = BASS_SampleLoad(false, "1.mp3", 0, 0, 1, BASS_SAMPLE_MONO);
    HCHANNEL channel=BASS_SampleGetChannel(sample, FALSE); 
    BASS_ChannelPlay(channel, FALSE); 
    system("pause");
    return 0;
}

I tried really different initialization setting etc. Nothing seemed to be working. The '1.mp3' file is in the debug folder of my "app". Thanks in advance!

Sample for playing must be of void* type. Try as I did:

//path to file 
string *filePath = new string("/home/user/Qt-Projects/bass/sample.mp3");

Function to reduct to type void* :

const void* getFile(string* file){
    return file->data();
}

And finish:

streamHandle = BASS_StreamCreateFile(false, getFile(filePath), 0, 0, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM