PDA

View Full Version : [Lập trình C++] Gấp !Cần cao thủ chuyên lập trình giải quyết giúp !


steel_dragon
05-10-2010, 00:01
Em có file code của 1 chương trình mp3 player viết bằng C++ sử dụng thư viện BASS và wxWidgets
Mô tả: chương trình chỉ đọc file MP3 và có các nút cơ bản (play, stop, ...)

Tuy nhiên, em ko làm sao mà chạy được , bác nào có thời gian rỗi ngâm cứu cho nó chạy , em xin hậu tạ (1 chầu cafe + thù lao tương xứng)

main.h:

#ifndef __MAIN_H__
#define __MAIN_H__
#include <wx/wx.h>

#include "simple.h"
#include "bass.h"

class MyApp : public wxApp
{
public:
virtual bool OnInit();
virtual int OnExit();
};

#endif // __MAIN_H__
main.cpp

#include "main.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
if ( HIWORD( BASS_GetVersion() ) != BASSVERSION )
{
wxMessageBox( wxT("Invalid BASS.DLL Version"), wxT("BASS.DLL Error") );
return false;
}

if ( !BASS_Init( -1, 44100, 0,0,NULL) )
{
wxMessageBox( wxT("BASS Init Error"), wxT("BASS.DLL Error") );
return false;
}


Simple *simple = new Simple(wxT("Simple"));
simple->Show(true);

return true;
}

int MyApp::OnExit()
{
BASS_Free();

return true;
}
simple.h

#ifndef __SIMPLE_H__
#define __SIMPLE_H__
#include <wx/wx.h>
#include <wx/filedlg.h>
#include <wx/filename.h>

#include "bass.h"

//Pre Define Class
class Simple;
class SimpleTimer;

enum
{
wxIDSimple_Open = 1000,
wxIDSimple_Play,
wxIDSimple_Stop,
wxIDSimple_TextPanel
};

class Simple : public wxFrame
{
public:
Simple(const wxString& title);

void OnOpen(wxCommandEvent & event);
void OnPlay(wxCommandEvent & event);
void OnStop(wxCommandEvent & event);

//Buttons Poinsters
wxButton *m_OpenButton;
wxButton *m_PlayButton;
wxButton *m_StopButton;

//Text Display
wxStaticText *m_text;
wxString m_FileName;

// Timer Task
SimpleTimer *m_timer;

//Bass
HSTREAM channel;
};

class SimpleTimer : public wxTimer
{
public:
SimpleTimer( Simple *frame )
{
m_frame = frame;
}

void Notify();
Simple *m_frame;
};

#endif // __SIMPLE_H__
simple.cpp

#include "simple.h"

Simple::Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(242, 100), wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
//SetIcon(wxICON(iconresource)); // Enable this if you want to build with resources

//Set Channel to 0
channel = 0;

wxPanel *panel = new wxPanel(this, wxID_ANY);

// Buttons
m_OpenButton = new wxButton(panel, wxIDSimple_Open, wxT("Open"), wxPoint(5, 5));
Connect(wxIDSimple_Open, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(Simple::OnOpen));
m_OpenButton->SetFocus();

m_PlayButton = new wxButton(panel, wxIDSimple_Play, wxT("Play"), wxPoint(80, 5));
Connect(wxIDSimple_Play, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(Simple::OnPlay));
m_PlayButton->SetFocus();
m_PlayButton->Disable();

m_StopButton = new wxButton(panel, wxIDSimple_Stop, wxT("Stop"), wxPoint(155, 5));
Connect(wxIDSimple_Stop, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(Simple::OnStop));
m_StopButton->SetFocus();
m_StopButton->Disable();

//Text
m_text = new wxStaticText(panel, wxIDSimple_TextPanel, wxT(""), wxPoint(5, 30), wxSize( 228, 50 ), wxALIGN_CENTRE );
m_text->SetFocus();

//Timer Task
m_timer = new SimpleTimer(this);
m_timer->Start( 500 );

Centre();
}

void Simple::OnOpen(wxCommandEvent & WXUNUSED(event))
{
wxFileDialog fd(this, wxFileSelectorPromptStr, wxEmptyString, wxEmptyString, wxT("streamable files|*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aif") );

if(fd.ShowModal() == wxID_OK)
{
BASS_StreamFree( channel );
channel = BASS_StreamCreateFile(FALSE, fd.GetPath(), 0, 0, BASS_SAMPLE_LOOP );
if( channel != NULL )
{
m_StopButton->Enable();
m_PlayButton->Enable();
m_PlayButton->SetLabel( wxT("Pause") );
BASS_ChannelPlay( channel, true );

m_FileName = wxFileName(fd.GetPath()).GetName();
}
else
{
m_StopButton->Disable();
m_PlayButton->Disable();
m_PlayButton->SetLabel( wxT("Play") );
}
}
}

void Simple::OnPlay(wxCommandEvent & WXUNUSED(event))
{
if( BASS_ChannelIsActive( channel ) != BASS_ACTIVE_PLAYING )
{
BASS_ChannelPlay( channel, BASS_ChannelIsActive( channel ) == BASS_ACTIVE_PAUSED ? false : true );
m_PlayButton->SetLabel( wxT("Pause") );
}
else
{
BASS_ChannelPause( channel );
m_PlayButton->SetLabel( wxT("Play") );
}

m_StopButton->Enable();
}

void Simple::OnStop(wxCommandEvent & WXUNUSED(event))
{
BASS_ChannelStop( channel );
m_PlayButton->SetLabel( wxT("Play") );
m_StopButton->Disable();
}


void SimpleTimer::Notify()
{
if( m_frame->channel == 0 )
{
m_frame->m_text->SetLabel( wxT("") );
return;
}

// Yes this can do it only on file open!! But is a simple example. (totaltime)
double postime = BASS_ChannelBytes2Seconds(m_frame->channel, BASS_ChannelGetPosition(m_frame->channel, BASS_POS_BYTE));
double totaltime = BASS_ChannelBytes2Seconds(m_frame->channel, BASS_ChannelGetLength(m_frame->channel, BASS_POS_BYTE));

m_frame->m_text->SetLabel( wxString::Format( wxT("%02i:%02i/%02i:%02i\n%s"), (long)(postime / 60), (long)((long)postime % 60), (long)(totaltime / 60), (long)((long)totaltime % 60), m_frame->m_FileName ) );
m_frame->m_text->SetSize( 228, 50 ); // Re format text in lines.
}

panjuan
05-10-2010, 00:05
Giữa kì hả bợn :sweat::sweat::sweat::sweat:

Mr.Over
05-10-2010, 00:07
ko học c++ học c# thôi

_sharp_
05-10-2010, 00:09
Giữa kì hả bợn :sweat::sweat::sweat::sweat:

ề thi giữa kì của trường nào hả bác :stick:

vetlantram_92qn
05-10-2010, 00:09
bác kiếm cái code này ở đâu ra thế :nosebleed:

FunnyKids
05-10-2010, 00:14
Debug qua mạng kiểu này lười lắm :D bạn cho cái error code lên thì may ra em còn giúp được ... Chứ bảo em tìm cái thư viện đấy về rồi compile cái này thì hơi ngại :D

steel_dragon
05-10-2010, 00:25
Các bác cố gắng giúp em phát, thực ra thì em ko có khả năng lập trình, trước giờ chỉ học mấy cái căn bản thôi
Kiểu gì thì miễn chạy đc là đc
Hoặc các bác viết cho em 1 code mới cũng đc

Em sẽ thỏa thuận thù lao với bác !

kunkka
05-10-2010, 01:26
VB thì còn nói được, chứ chơi C++ viết code đọc mp3 thì em chào thua :-s

maxx
05-10-2010, 02:02
compile rồi quăng lỗi lên đây đi bạn ^^ chứ vậy sao mà giúp :X

VoT
05-10-2010, 02:40
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions

"ComeauTest.c", line 1: error: this declaration has no storage class or type
specifier, Wild guess: Should this be in a function block?
Wild Guess: You're using export but not using Comeau C++ 4.3.x
main.h:
^

"ComeauTest.c", line 1: error: expected a ";" (perhaps on the previous statement)
main.h:
^

"ComeauTest.c", line 5: catastrophic error: could not open source file "wx/wx.h"
#include <wx/wx.h>
^

2 errors and 1 catastrophic error detected in the compilation of "ComeauTest.c".
Compilation terminated.

Có phải Error như thế này ko?

steel_dragon
05-10-2010, 21:02
Thực ra nó là 4 file , main.h, main.cpp, simple.h, simple.cpp :|

quannt89
05-10-2010, 21:04
Mình đã chạy được rồi nhưng mà cấu hình hơi phức tạp, có gì thì liên hệ với mình qua yahoo: quan_nguyen118

buonnguchannhan
05-10-2010, 21:09
Các bác cố gắng giúp em phát, thực ra thì em ko có khả năng lập trình, trước giờ chỉ học mấy cái căn bản thôi
Kiểu gì thì miễn chạy đc là đc
Hoặc các bác viết cho em 1 code mới cũng đc

Em sẽ thỏa thuận thù lao với bác !
Đi du học vì mục đích gì đây ?
Bao giờ về nước bố mẹ xin cho cái chân nhà nước à :tire:
Nếu không thích học thì biểu bố mẹ cho sang học ngành khác đê :sad:

steel_dragon
05-10-2010, 22:06
Đi du học vì mục đích gì đây ?
Bao giờ về nước bố mẹ xin cho cái chân nhà nước à :tire:
Nếu không thích học thì biểu bố mẹ cho sang học ngành khác đê :sad:

Vâng , em đang đi ngoài ra nước đây , bác nào giúp em đê :stick: