Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Como Cargar un Archivo de Audio (https://www.clubdelphi.com/foros/showthread.php?t=78085)

Jusar 19-03-2012 19:12:25

Como Cargar un Archivo de Audio
 
Hola gente me podrian ayudar a ver como hago para poder cargar un archivo de audio extencion .mp3 para que mientras reprodusco el programa esta se ejecute hasta que se cierre...

ecfisa 19-03-2012 22:21:21

Hola Jusar.

Podés utilizar el componente TMediaPlayer.

Por ejemplo:
Código:

...
#include<mplayer.hpp>
#define MP3_FILE "C:\\Users\\User\\Music\\Sound.mp3" /* ruta+nombre_archivo */

TMediaPlayer *mp = new TMediaPlayer(Form1);

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  mp->Parent = this;
  mp->Visible = false;
  mp->FileName = MP3_FILE;
  mp->AutoRewind = true;
  mp->AutoOpen = true;
  mp->OnNotify = MediaPlayerNotify;
  mp->Open();
  mp->Play();
}

void __fastcall TForm1::MediaPlayerNotify(TObject *Sender)
{
  if (mp->NotifyValue == nvSuccessful ){
  mp->Play();
  mp->Notify = true;
  }
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  mp->Close();
  delete mp;
}

También y más simple aún, pones el componente desde la paleta System y ajustas sus propiedades desde el Object Inspector.
Código:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
 MediaPlayer1->Open();
 MediaPlayer1->Play();
}

void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{
 if (MediaPlayer1->NotifyValue == nvSuccessful ){
  MediaPlayer1->Play();
  MediaPlayer1->Notify = true;
  }
}


Un saludo.

escafandra 20-03-2012 21:48:18

Otra posibilidad usando API de Windows:

Si el sonido es un archivo wav:
Código:

PlaySound("C:\\WINDOWS\\ServicePackFiles\\i386\\xpstartu.wav", HInstance, SND_FILENAME);
Para cualquier archivo multimedia audio o vídeo:

Código:

Sound(String FileName)
{
  mciSendString("close media", NULL, 0, 0);
  mciSendString(("open \"" + FileName + "\" alias media").c_str(), NULL, 0, 0);
  mciSendString("play media", NULL, 0, 0);
}


Saludos.

Jusar 21-03-2012 09:45:00

Gente no he podido hecharlo andar si me lo puideran explicar un poco se les agradeceria...

escafandra 21-03-2012 13:37:58

Cita:

Empezado por Jusar (Mensaje 428131)
Gente no he podido hecharlo andar si me lo puideran explicar un poco se les agradeceria...

¿Que es lo que no has podido echar a andar? ¿El ejemplo de ecfisa o los dos que puse yo?
Mejor expón tu duda o problema concreto y lo ponemos en marcha.


Saludos.


La franja horaria es GMT +2. Ahora son las 00:35:34.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi