Class pour manipuler le cd audio

Description

Juste une petite class pour gerer le cd audio
Si ca interese des personnes.

Utilisation de chaine mci. (mciSendString)

Source / Exemple :


LE fichier CD_AUDIO.h

typedef class cd_audio *	lpCd_audio;

//*************************************************************************************************/
/* Déclaration des classes*/
/**************************/
class cd_audio
{
/*Constructeur et destructeurs*/
public:
					cd_audio(HWND handle);				//Constructeur
					~cd_audio();						//Destructeur
/*Les Methodes*/
public:
			void	play_track(int no_track);
			void	play_track(char *beg_time,char *end_time);
			void	pause();
			BOOL	is_playing();
			BOOL	is_pause();
			void	stop();
			char	*cd_length();
			char	*cd_elapsed_time();
			char	*track_length(int no_track);
			char	*begin_time_for_track(int no_track);
			int		nb_track();

private:
			void	launch_mci_command(char *command);

/* Les Attributs*/
private:
	HWND	handle;
	BOOL	bplaying;
	BOOL	bpause;
	TCHAR	ret_mci_str[1024];
};

le fichier CD_AUDIO.cpp

#include "cd_audio.h"
/**********************************************************************************************/
/* Code Source de la classe cd_audio */
/*******************************/
cd_audio::cd_audio(HWND hwnd)
{
	bpause		= false;
	bplaying	= false;
	handle		= hwnd;
}
/*************************************************************************************************/
cd_audio::~cd_audio()
{
	launch_mci_command("stop cdaudio");
	launch_mci_command("eject cdaudio");
	launch_mci_command("close cdaudio");
}
/*************************************************************************************************/
void	cd_audio::play_track(int no_track)
{
	char	command[100];

	begin_time_for_track(no_track);
	sprintf(command,"play cdaudio from %s",begin_time_for_track(no_track));
	launch_mci_command(command);
	bplaying = true;
}
/*************************************************************************************************/
void	cd_audio::play_track(char *beg_time,char *end_time)
{
	char	command[100];

	sprintf(command,"play cdaudio from %s to %s",beg_time,end_time);
	launch_mci_command(command);
	bplaying = true;
}
/*************************************************************************************************/
void	cd_audio::pause()
{
static char	time[50];
char	command[100];

	if (bpause)
	{
		sprintf(command,"play cdaudio from %s",time);
		launch_mci_command(command);
		bpause = false;
	}
	else
	{
		strcpy(time,cd_elapsed_time());
		launch_mci_command("pause cdaudio");
		bpause = true;
	}
}
/*************************************************************************************************/
BOOL	cd_audio::is_playing()
{
	return (bplaying);
}
/*************************************************************************************************/
BOOL	cd_audio::is_pause()
{
	return (bpause);
}
/*************************************************************************************************/
void	cd_audio::stop()
{
	launch_mci_command("stop cdaudio");
	bplaying = false;
}
/*************************************************************************************************/
char	*cd_audio::cd_length()
{
	launch_mci_command("status cdaudio length");
	return (ret_mci_str);
}
/*************************************************************************************************/
char	*cd_audio::cd_elapsed_time()
{
	launch_mci_command("status cdaudio position");
	return (ret_mci_str);	
}
/*************************************************************************************************/
char	*cd_audio::track_length(int no_track)
{
	char	str[100];

	sprintf(str,"status cdaudio length track %d",no_track);
	launch_mci_command(str);
	return (ret_mci_str);
}
/*************************************************************************************************/
char	*cd_audio::begin_time_for_track(int no_track)
{
	char	str[100];

	sprintf(str,"status cdaudio position track %d",no_track);
	launch_mci_command(str);
	return (ret_mci_str);
}
/*************************************************************************************************/
int		cd_audio::nb_track()
{
	launch_mci_command("status cdaudio number of tracks");
	return (atoi(ret_mci_str));
}
/*************************************************************************************************/
void	cd_audio::launch_mci_command(char *command)
{
static	DWORD ret_len = sizeof(ret_mci_str) / sizeof(TCHAR);

	mciSendString(command, ret_mci_str,ret_len,handle);
}
/*************************************************************************************************/
/* Fin du fichier Source */
/*************************/

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.