Use multi-media library bass. DLL to play MP3 [3]-Open, play, pause, and stop

Source: Internet
Author: User
// Before playing the video, use the bass_init function to initialize the playing device. Function bass_init (device: integer; {specify the output device. The first is 1 and the second is 2; -1 indicates that the current device is used} freq: DWORD; {sampling rate, generally 44100} flags: DWORD; {it is the combination value of constants such as bass_device_mono and is the effect parameter; 0 is the default value} Win: hwnd; {specify the window handle; 0 indicates the current window} CLSID: pguid {specify a guid to initialize directsound; nil indicates using the default value}): bool; stdcall; External bassdll; // Of course, You need to load the file stream from the file or memory before playing function bass_streamcreatefile (MEM: bool; {loading from the file here is false; loading from memory here is true} f: pointer; {pointer to the file name or memory stream} offset: qword; {start point of playing, unit: 1/10 milliseconds; only in parameter 1: mem = false; default value: 0} length: qword; {Playback End Point, in 1/10 milliseconds; valid only when parameter 1: Mem = false; the default value is 0} flags: A combination of DWORD {bass_sample_3d and other parameters; controls playback effect, repetition, decoding, etc.}): hstream; stdcall; External bassdll; {In addition: when calling the memory stream, the parameter length must be specified as the stream size}

  

Form Design Drawing:


CodeFile:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) opendialog1: topendialog; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure upload (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject ); procedure button3click (Sender: tobjec T); Procedure button4click (Sender: tobject); Procedure formdestroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses bass; var HS: hstream; {stream handle} procedure tform1.formcreate (Sender: tobject); begin if hiword (bass_getversion) bassversion then MessageBox (0, '"Bass. the DLL file version is not suitable! ', Nil, mb_iconerror); if not bass_init (-1, 44100, 0, 0, nil) Then showmessage ('initialization error'); end; {open the MP3 file, and establish the playing stream} procedure tform1.button1click (Sender: tobject); var mp3path: ansistring; begin {open file} opendialog1.filter: = 'mp3 file (*. MP3) | *. MP3 | WAV file (*. wav) | * WAV '; If opendialog1.execute then mp3path: = ansistring (opendialog1.filename); {if an existing file is opened, release it first} bass_streamfree (HS); {create a stream} HS: = bass_streamcreatefile (false, pansichar (mp3path), 0, 0, 0); {whether enabled successfully, show it} if hs

Form file:

Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 117 clientwidth = 202 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate ondestroy = formdestroy pixelsperinch = 96 textheight = 13 object button1: tbutton left = 16 Top = 17 width = 75 Height = 25 caption = #25171 #24320 taborder = 0 onclick = button1click end object button2: tbutton left = 112 Top = 17 width = 75 Height = 25 caption = #25773 #25918 taborder = 1 onclick = button2click end object button3: tbutton left = 112 Top = 48 width = 75 Height = 25 caption = #26242 #20572 taborder = 2 onclick = button3click end object button4: tbutton left = 112 Top = 79 width = 75 Height = 25 caption = #20572 #27490 taborder = 3 onclick = button4click end object opendialog1: topendialog left = 40 top = 56 endend
 
  
 
Related Article

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.