Delphi with Multimedia library Bass.dll play MP3 [7]

Source: Internet
Author: User
Tags exit

This example effect chart:

Code files:

Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Extctrls;
Type
TForm1 = Class (Tform)
Opendialog1:topendialog;
Timer1:ttimer;
Button1:tbutton;
Button2:tbutton;
Button3:tbutton;
Button4:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
Procedure Button3click (Sender:tobject);
Procedure Button4click (Sender:tobject);
Procedure Timer1timer (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Bass;
Var
Hs:hstream; {Stream Handle}
Procedure Tform1.formcreate (Sender:tobject);
Begin
Timer1.interval: = 200;
If HiWord (bass_getversion) <> Bassversion Then
MessageBox (0, "Bass.dll" file version is not suitable!) ', nil, mb_iconerror);
If not Bass_init ( -1, 44100, 0, 0, nil) then
ShowMessage (' initialization error ');
End
Open
Procedure Tform1.button1click (Sender:tobject);
Var
mp3path:ansistring;
Begin
Bass_streamfree (HS);
Opendialog1.filter: = ' Mp3 file (*.mp3) |*.mp3| Wav file (*.wav) |*wav ';
If Opendialog1.execute Then
Mp3path: = ansistring (Opendialog1.filename);
HS: = Bass_streamcreatefile (False, Pansichar (Mp3path), 0, 0, 0);
{Want to set up the playback stream as follows, just loop the play}
HS: = Bass_streamcreatefile (False, Pansichar (Mp3path), 0, 0, bass_sample_loop);
If HS < bass_error_ended then Text: = ' Open failed '
End
Play
Procedure Tform1.button2click (Sender:tobject);
Begin
Bass_channelplay (HS, False);
End
Suspended
Procedure Tform1.button3click (Sender:tobject);
Begin
Bass_channelpause (HS);
End
Stop
Procedure Tform1.button4click (Sender:tobject);
Begin
Bass_channelstop (HS);
End
{Monitoring Playback status}
Procedure Tform1.timer1timer (Sender:tobject);
Var
str:string;
Begin
If hs = 0 Then Exit; {Exit} if the playback stream is not established
Case Bass_channelisactive (HS) of
BASS_ACTIVE_STOPPED:STR: = ' stop state ';
Bass_active_playing:str: = ' playing ';
BASS_ACTIVE_STALLED:STR: = ' stall state, waiting for data ';
BASS_ACTIVE_PAUSED:STR: = ' suspend state ';
End
Text: = str;
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Bass_free;
End
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.