unyelin
一般會員
發表:4 回覆:3 積分:1 註冊:2004-06-28
發送簡訊給我
|
各位你們好…
我現在正寫一個能播放mp3的bcb程式…
目前雖已做到能連續播放…可是在連續播放四~五首歌後…
就會發出下面的訊息
Project xxx.exe raised exception class EMCIDeviceError with
message 起始設定MCI時發生問題。
請問這是指什麼錯誤的發生呢~,發生這問題時有搜尋之前是否有類似
問題發生,雖有看過一篇很類似 …可是他是不能發出聲音…,
可是我是能播放約4~5首後…才會發生這錯誤…這意味著什麼呢~
謝謝您的解答
^^
------ ^^
|
李國維
高階會員
發表:42 回覆:287 積分:235 註冊:2003-02-07
發送簡訊給我
|
unyelin:
請問一下.在每首歌開始前.是否有先做過MideaPlayer1->Close();
這各動作.如果沒有在可以試試看.
|
unyelin
一般會員
發表:4 回覆:3 積分:1 註冊:2004-06-28
發送簡訊給我
|
您好…謝謝您的回覆~
可是我在播放時…確有已做MediaPlayer1->Close的動作…
這是我的程式請參考…
我參考之前前輩們用 deiphi寫的程式…翻成BcB
功能是想寫能播放mp3檔時…同時show出歌詞…
其實…有一點是很疑惑…
就是…程式執行時…
每次播了四、五首(有時能播更多…)…就會有上述問題發生
可是…如果我在程式中設斷點去debug...看看是不是我寫錯了…
可是又能一直追蹤播放到十幾首去,沒有問題…(當然…每執行一首就要
在斷點上按f9,使之再play)
與朋友討論後…想說…是不是程式在一首首直接播放的時候
佔掉太多的memory空間類似的問題…
可是…由於程式還不夠強…所以…不知是不是這問題…
若是的話…也不知如何解決…
謝謝您的回答…
#include "vcl.h"
#include "string.h"
#include "stdio.h"
#include
#pragma hdrstop
#include "music.h"
#include "lyric.h"
#include "dir.h"
#include "FilenameDeal.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString ModeStr[] = {"Not ready", "Stopped", "Playing", "Recording", "Seeking", "Paused", "Open"};
int count = 0;
int guard = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DragAcceptFiles(Handle,true);
MediaPlayer1->Notify = true;
MediaPlayer1->AutoRewind = true;
}
//---------------------------------------------------------------------------
void __fastcall lyric_show(char *Lyric_Filename)
{
for( int i = 0; ; i )
{
if(Lyric_Filename[i] == '.')
{
Lyric_Filename[i] = '\0';
break;
}
}
Form2->Memo1->Font = Form2->FontDialog1->Font;
Lyric_Filename = StrCat(Lyric_Filename, ".txt");
String Lyric_Path_Filename = "C:\\Documents and Settings\\Administrator\\桌面\\0728英文歌詞\\";
Lyric_Path_Filename = Lyric_Path_Filename String(Lyric_Filename);
if(!FileExists(Lyric_Path_Filename))
{
Form2->Memo1->Lines->Clear();
Form2->Memo1->Lines->Add("isn't exist!");
return;
}
Form2->Memo1->Lines->LoadFromFile(Lyric_Path_Filename);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{
Form1->Caption = ModeStr[(int) MediaPlayer1->Mode];
if(guard == 1)
{
guard = 0;
return;
}
String mp3FilePath = txtFolder->Caption mp3List->Items->Strings[mp3List->ItemIndex count];
if(!FileExists(mp3FilePath))
{ ShowMessage("MP3 file does not exist?!"); return;} if (MediaPlayer1->NotifyValue == nvSuccessful)
{
if (count != 0)
{
//lyric_show(String(mp3File.get_filename()));
char *lyric_name = mp3List->Items->Strings[mp3List->ItemIndex count].c_str();
lyric_show(lyric_name);
MediaPlayer1->Close();
MediaPlayer1->DeviceType = dtAutoSelect;
MediaPlayer1->FileName = mp3FilePath;
MediaPlayer1->Open();
MediaPlayer1->Play();
Progres->Max = MediaPlayer1->Length;
Timer1->Enabled = true;
ProgresTimer->Enabled =true;
guard = 1;
}
mp3FilePath = mp3FilePath;
}
else if (MediaPlayer1->NotifyValue == nvSuperseded)
{
mp3FilePath = mp3FilePath;
}
else if (MediaPlayer1->NotifyValue == nvAborted)
{
mp3FilePath = mp3FilePath;
return;
}
else if (MediaPlayer1->NotifyValue == nvFailure)
{
mp3FilePath = mp3FilePath;
}
/* Note we must reset the Notify property to so that we are notified the next time the mode changes */
MediaPlayer1->Notify = true;
count ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnDropFiles(TWMDropFiles & Msg)
{
/*
DWORD nFileNameSize=DragQueryFile( (HDROP)Msg.Drop,0,NULL,0); // 取得拖曳過來的檔名大小
char *sFileName = new char[nFileNameSize 1];
DragQueryFile((HDROP)Msg.Drop,0,sFileName,nFileNameSize 1); // 取得拖曳過來的檔案的檔名:sFileName
FileDeal mp3file(sFileName);
FileDeal lyric;
if (mp3file.Fnsplit_Filename())
Filewindow->Lines->Add(IntToStr(count) ". " String(mp3file.get_filename()));
else
{Filewindow->Lines->Add("0"); return ;}
//"C:\\Documents and Settings\\Administrator\\桌面\\英文歌詞\\11_WITHOUT YOU.TXT"
lyric.FilePathName_Set("C:",
"\\Documents and Settings\\Administrator\\桌面\\英文歌詞\\",
mp3file.get_filename(),
".txt");
lyric.FilePathName_StrCat();
Form2->Memo1->Font = Form2->FontDialog1->Font;
Form2->Memo1->Lines->LoadFromFile(lyric.get_FilePathName());
MediaPlayer1->AutoEnable = true;
Timer1->Enabled = true;
ProgresTimer->Enabled =true;
Form1->Filewindow->SelAttributes->Color = clWhite;
Progres->Max = 0;
MediaPlayer1->Close();
MediaPlayer1->DeviceType = dtAutoSelect;
MediaPlayer1->FileName = sFileName;
MediaPlayer1->Open();
MediaPlayer1->Play();
Progres->Max = MediaPlayer1->Length;
ProgresTimer->Enabled =true;
delete []sFileName;
*/
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CloseClick(TObject *Sender)
{
MediaPlayer1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Font = FontDialog1->Font;
union
{
long Data;
unsigned char TT[4];
}TimeData;
char Display[100] = "";
if(MediaPlayer1->Mode != mpPlaying) return;
MediaPlayer1->TimeFormat = tfSMPTE30;
TimeData.Data = MediaPlayer1->Position;
sprintf(Display, "%d:%d:%d:%d",TimeData.TT[3],TimeData.TT[2],TimeData.TT[1] /= 4.27,TimeData.TT[0]);
Label1->Caption = Display;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ProgresTimerTimer(TObject *Sender)
{
if (Progres->Max != 0)
Progres->Position = MediaPlayer1->Position;
}
//---------------------------------------------------------------------------
void __fastcall FillMP3FileList(String Folder)
{
TSearchRec Rec;
int count_file = 1;
Form1->mp3List->Items->Clear();
if (FindFirst(Folder "*.mp3", faAnyFile, Rec) == 0)
{
//回傳成功
do
{
Form1->mp3List->Items->Add(Rec.Name);
}while(FindNext(Rec)== 0);
FindClose(Rec);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnOpenFolderClick(TObject *Sender)
{
String mp3Folder;
if(OpenDialog1->Execute())
mp3Folder = ExtractFilePath(OpenDialog1->FileName);
if(mp3Folder == NULL)
return;
txtFolder->Caption = mp3Folder;
FillMP3FileList(mp3Folder);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::mp3ListDblClick(TObject *Sender)
{
if (mp3List->Items->Count == 0)
return;
String mp3FilePath = txtFolder->Caption mp3List->Items->Strings[mp3List->ItemIndex];
String temp1 = mp3List->Items->Strings[mp3List->ItemIndex];
char *lyric_name = temp1.c_str();
if(!FileExists(mp3FilePath))
{
ShowMessage("MP3 file does not exist?!");
return;
}
lyric_show(lyric_name);
Progres->Max = 0;
Timer1->Enabled = true;
MediaPlayer1->Close();
MediaPlayer1->DeviceType = dtAutoSelect;
MediaPlayer1->FileName = mp3FilePath;
MediaPlayer1->Open();
Progres->Max = MediaPlayer1->Length;
ProgresTimer->Enabled =true;
MediaPlayer1->Play();
guard = 0;
count = 0;
} ^^
------ ^^
|
aamihcom
一般會員
發表:57 回覆:40 積分:19 註冊:2003-10-02
發送簡訊給我
|
我想那應該是音效卡驅動程式的問題....因為我有遇過,driver重裝看看
|
unyelin
一般會員
發表:4 回覆:3 積分:1 註冊:2004-06-28
發送簡訊給我
|
^^,謝謝你們的回答…我想我應該解決了…
而且也滿足了我的需求…(雖還是很粗糙)
不過…我並沒有重裝音效卡的驅動程式…
而是把程式再改寫…目前只在xp上跑過…
程式的寫法如下…與大家一起分享
謝謝大家…
#include
#include "string.h"
#include "stdio.h"
#include
#pragma hdrstop
#include "music.h"
#include "lyric.h"
#include "dir.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString ModeStr[] = {"Not ready", "Stopped", "Playing", "Recording", "Seeking", "Paused", "Open"};
void __fastcall lyric_show(char *Lyric_Filename);
int count = 0;
int guard = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
MediaPlayer1->Notify = false;
MediaPlayer1->AutoRewind = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{
Form1->Caption = ModeStr[(int) MediaPlayer1->Mode];
if (MediaPlayer1->NotifyValue == nvSuccessful)
{
if (FileListBox1->ItemIndex == Form1->FileListBox1->Items->Count - 1)
{
FileListBox1->ItemIndex = -1;
// return;
} if(FileListBox1->ItemIndex != 187)
FileListBox1->ItemIndex ;
Form2->Memo1->Font = Form1->FontDialog1->Font;
String mp3FilePath = Form1->txtFolder->Caption Form1->FileListBox1->Items->Strings[FileListBox1->ItemIndex];
Form1->FileListBox1->Focused();
String temp1 = Form1->FileListBox1->Items->Strings[FileListBox1->ItemIndex];
char *lyric_name = temp1.c_str();
if(!FileExists(mp3FilePath))
{
ShowMessage("MP3 file does not exist?!");
return;
}
lyric_show(lyric_name);
Form1->Progres->Max = 0;
Form1->TrackBar1->Max = 0;
Form1->Timer1->Enabled = true;
Form1->MediaPlayer1->Close();
Form1->MediaPlayer1->DeviceType = dtAutoSelect;
Form1->MediaPlayer1->FileName = mp3FilePath;
Form1->MediaPlayer1->Open();
Form1->MediaPlayer1->Play();
Form1->Progres->Max = Form1->MediaPlayer1->Length;
Form1->TrackBar1->Max = Form1->MediaPlayer1->Length;
Form1->ProgresTimer->Enabled =true;
}
else if (MediaPlayer1->NotifyValue == nvSuperseded)
{
}
else if (MediaPlayer1->NotifyValue == nvAborted)
{
return;
}
else if (MediaPlayer1->NotifyValue == nvFailure)
{
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnDropFiles(TWMDropFiles & Msg)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CloseClick(TObject *Sender)
{
MediaPlayer1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Font = FontDialog2->Font;
union
{
long Data;
unsigned char TT[4];
}TimeData;
char Display[100] = "";
if(MediaPlayer1->Mode != mpPlaying) return;
MediaPlayer1->TimeFormat = tfSMPTE30;
TimeData.Data = MediaPlayer1->Position;
sprintf(Display, "%d:%d:%d:%d",TimeData.TT[3],TimeData.TT[2],TimeData.TT[1] /= 4.27,TimeData.TT[0]);
Label1->Caption = Display;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ProgresTimerTimer(TObject *Sender)
{
if (Progres->Max != 0)
{
Progres->Position = MediaPlayer1->Position;
TrackBar1->Position = MediaPlayer1->Position;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnOpenFolderClick(TObject *Sender)
{
String mp3Folder;
FileListBox1->Font = FontDialog1->Font;
if(OpenDialog1->Execute())
{
mp3Folder = ExtractFilePath(OpenDialog1->FileName);
FileListBox1->FileName = mp3Folder;
}
if(mp3Folder == NULL)
return;
txtFolder->Caption = mp3Folder;
}
//---------------------------------------------------------------------------
void __fastcall lyric_show(char *Lyric_Filename)
{
for( int i = 0; ; i )
{
if(Lyric_Filename[i] == '.')
{
Lyric_Filename[i] = '\0';
break;
}
}
Form2->Memo1->Font = Form2->FontDialog1->Font;
Lyric_Filename = StrCat(Lyric_Filename, ".txt");
String Lyric_Path_Filename = "C:\\Documents and Settings\\Administrator\\桌面\\歌詞\\";
Lyric_Path_Filename = Lyric_Path_Filename String(Lyric_Filename);
if(!FileExists(Lyric_Path_Filename))
{
Form2->Memo1->Lines->Clear();
Form2->Memo1->Text = "The song " String(Lyric_Filename) " isn't exist!";
return;
}
Form2->Memo1->Lines->LoadFromFile(Lyric_Path_Filename);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileListBox1DblClick(TObject *Sender)
{
if (Form1->FileListBox1->Items->Count == 0)
return;
//count = FileListBox1->ItemIndex;
Form2->Memo1->Font = Form1->FontDialog1->Font;
//String mp3FilePath = Form1->txtFolder->Caption Form1->FileListBox1->Items->Strings[count];
String mp3FilePath = Form1->txtFolder->Caption Form1->FileListBox1->Items->Strings[FileListBox1->ItemIndex];
String temp1 = Form1->FileListBox1->Items->Strings[FileListBox1->ItemIndex];
char *lyric_name = temp1.c_str();
if(!FileExists(mp3FilePath))
{
ShowMessage("MP3 file does not exist?!");
return;
}
lyric_show(lyric_name);
Form1->Progres->Max = 0;
Form1->TrackBar1->Max = 0;
Form1->Timer1->Enabled = true;
Form1->MediaPlayer1->Close();
Form1->MediaPlayer1->DeviceType = dtAutoSelect;
Form1->MediaPlayer1->FileName = mp3FilePath;
Form1->MediaPlayer1->Open();
Form1->MediaPlayer1->Play();
Form1->Progres->Max = Form1->MediaPlayer1->Length;
Form1->TrackBar1->Max = Form1->MediaPlayer1->Length;
Form1->ProgresTimer->Enabled =true;
} ^^
------ ^^
|