Simple example of gapless playing.
This example will play 3 songs gapless.
Note: You can add multiple files to gapless queue.
Note: You can add miscellaneous streams to gapless queue. First song can be mp3, second ogg, third again mp3, ...
/* * libZPlay example * * Gapless playing of 3 files. * * Use callback mechanism to get information on song change */ #include <windows.h> #include <stdio.h> #include <conio.h> #include "libzplay.h" using namespace libZPlay; // callback function prototype int __stdcall myCallbackFunc(void* instance, void *user_data, TCallbackMessage message, unsigned int param1, unsigned int param2); int main(int argc, char **argv) { printf("Gapless playing of 3 files.\n\nPress q to end\n\n"); // create class instance using class factory. ZPlay *player = CreateZPlay(); // set callback mechanism to intercept MsgNextSongAsync message // this message is sent when one next fong from gapless queue starts playing player->SetCallbackFunc(myCallbackFunc, (TCallbackMessage) (MsgNextSongAsync), 0); // add first file to gapless queue int result = player->AddFile("test.mp3", sfAutodetect); if(result == 0) { // display error message printf("Error: %s\n", player->GetError()); player->Release(); return 0; } // add second file to gapless queue result = player->AddFile("test1.mp3", sfAutodetect); if(result == 0) { // display error message printf("Error: %s\n", player->GetError()); } // add third fiel to gapless queue result = player->AddFile("test2.mp3", sfAutodetect); if(result == 0) { // display error message printf("Error: %s\n", player->GetError()); } // start playing player->Play(); // display position and wait for song end while(1) { // check key press if(kbhit()) { int a = getch(); if(a == 'q' || a == 'Q') break; // end program if Q key is pressed } // get stream status to check if song is still playing TStreamStatus status; player->GetStatus(&status); if(status.fPlay == 0) break; // exit checking loop // get current position TStreamTime pos; player->GetPosition(&pos); // display position printf("Pos: %02u:%02u:%02u:%03u\r", pos.hms.hour, pos.hms.minute, pos.hms.second, pos.hms.millisecond); Sleep(300); // wait 300 ms } // destroy class instance player->Release(); return 0; } int __stdcall myCallbackFunc(void* instance, void *user_data, TCallbackMessage message, unsigned int param1, unsigned int param2) { ZPlay *myinstance = (ZPlay*) instance; switch(message) { case MsgNextSongAsync: // next song from gapless queue starts playing { printf("Playing song: %u - Left in queue: %u\n", param1, param2); } return 0; } return 0; }
Copyright (c) 2010. Zoran Cindori - All rights reserved.
Web: http://libzplay.sourceforge.net/ Email: zcindori@inet.hr |