0
0

Hello,
I’m working on a small music player class and I’m having a hard time setting the callback function for when a song has finished playing so I could start the next one in the list. I’ve looked through the stream example included with the API and it looks fairly straightforward, however, when I try to use the FSOUND_Stream_SetEndCallback function I recieve an error saying
[quote:193f7k8c]
error C2664: ‘FSOUND_Stream_SetEndCallback’ : cannot convert parameter 2 from ‘signed char (FSOUND_STREAM *,void *,int,void *)’ to ‘FSOUND_STREAMCALLBACK’
[/quote:193f7k8c]

I don’t understand what I’m doing wrong though. If someone could help point me in the right direction I would really appreciate it.

Here is the code for my player class:
[code:193f7k8c]
//Implementation of the player class

include "stdafx.h"

include "player.h"

include <iostream>

include <fstream>

//Default constructor. Initializes FMOD.
player::player()
{
FSOUND_Init(44100, 32, 0); //Initialize the sound system
song=NULL;
paused=FALSE;
listloaded=FALSE;
currentsong=NULL;
FSOUND_Stream_SetBufferSize(1000);
}

//Default destructor
player::~player()
{
FSOUND_Close();
}

//Plays the song passed to it in the arg list
void player::PlaySong(string filename)
{

// Test to see if a song is already playing.  If it is, then stop it.
FSOUND_Stream_Stop(song);

song=FSOUND_Stream_Open(filename.c_str(),FSOUND_NORMAL, 0, 0);

            //This line gives me the error...
FSOUND_Stream_SetEndCallback(song, endcallback, NULL);

            FSOUND_Stream_Play(FSOUND_FREE, song);

}

//Pauses or unpauses the audio stream
void player::Pause()
{
if (paused==TRUE)
{
paused=FALSE; //Toggle paused status
}else
{
paused=TRUE;//pause playback
}

FSOUND_SetPaused(FSOUND_ALL, paused);

}

void player::Stop()
{
FSOUND_Stream_Stop(song);
}

//Loads the playlist specified in the file "name"
void player::LoadList(string name)
{
string temp;
SongInfo *ptr_song;
ifstream input;

playlist.clear();  //Clears out the old list if there was one

input.open(name.c_str(), ios::in);

if (! input.is_open())
{
    MessageBox(NULL, &quot;input file not open&quot;, &quot;Error&quot;, MB_OK);
}

//Open the playlist file to load the pointers to the songs in the list
while(!input.eof())
{
    ptr_song= new SongInfo;
    input &gt;&gt; temp;
    ptr_song-&gt;filename=temp;
    playlist.push_back(*ptr_song);
    delete ptr_song;
}

listloaded=TRUE;
currentsong=playlist.begin();

}

void player::ClearList()
{
playlist.clear();
listloaded=FALSE;
}

void player::PlayList()
{
//Set the callback function here.
//FSOUND_Stream_SetEndCallback();
PlaySong((*currentsong).filename);

}

signed char F_CALLBACKAPI player::endcallback(FSOUND_STREAM *stream, void *buff, int len, void *param)
{
MessageBox(NULL,"Song Over","...",MB_OK);
return 0;
}
[/code:193f7k8c]

here is the header file also:
[code:193f7k8c]
/*********************************************************************
* Header file for the player class
* player class will contain a linked list, which is the playlist
* plus it will contain the pointer to FSOUND_STREAM which is currently playing
* It will initialize FMOD when it is initialized. It will control song traversal
* and contain the callback for when a song has ended.
*********************************************************************/

ifndef PLAYER_H

include <list>

include <string>

include "fmod.h"

using namespace std;

struct SongInfo
{
string filename;
};

class player
{
public:
//Constructor
player();
~player();

//Member functions
void PlaySong(string filename);
void LoadList(string name);
void ClearList();
void Pause();
void PlayList();
//void CreateList();
void Stop();

//void VolumeUp();
//void VolumeDown();

signed char F_CALLBACKAPI endcallback(FSOUND_STREAM *stream, void *buff, int len, void *param);

private:
//Data members
FSOUND_STREAM *song; //pointer to the song to play
signed char paused;
signed char listloaded;
list<SongInfo> playlist;
list<SongInfo>::iterator currentsong;

//I need to put the callback function in here for when a song stops

};

define PLAYER_H

endif

[/code:193f7k8c]

Anyway, thanks again if anyone can help on this. I’ve been working on it for a couple hours now and I just can figure out what I’m doing wrong…

-Ranthalion

  • You must to post comments
0
0

try moving the callback funciton outside the class then passing a pointer to the class as param when you set the callback

  • You must to post comments
0
0

[code:27fpo7yu]
class player
{
public:
//Constructor
player();
~player();

//Member functions
void PlaySong(string filename);
void LoadList(string name);
void ClearList();
void Pause();
void PlayList();
//void CreateList();
void Stop();

//void VolumeUp();
//void VolumeDown();

static signed char F_CALLBACKAPI endcallback(FSOUND_STREAM *stream, void *buff, int len, void *param);

private:
//Data members
FSOUND_STREAM *song; //pointer to the song to play
signed char paused;
signed char listloaded;
list<SongInfo> playlist;
list<SongInfo>::iterator currentsong;

//I need to put the callback function in here for when a song stops
};
[/code:27fpo7yu]

The callback must be a static member.

  • You must to post comments
0
0

Thanks, I’ll give that a shot.

static worked like a charm.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.