Use multi-media library bass. DLL to play MP3 [4]-display and set the playback progress

Source: Internet
Author: User
// Obtain the length of the file stream, in the unit of byte function bass_channelgetlength (handle: DWORD; {stream handle} mode: DWORD {acquisition mode; there are two options, however, hstream can only use bass_pos_byte}): qword; stdcall; External bassdll; // gets the current pointer position of the stream, in the unit of byte function bass_channelgetposition (handle: DWORD; {stream handle} mode: DWORD {retrieval mode; two options are available, but the hstream can only use bass_pos_byte}): qword; stdcall; External bassdll; // obtain the time point based on the stream pointer position, in seconds. It is a very precise floating point function bass_channelbytes2seconds (handle: DWORD; {stream handle} pos: qword {stream pointer position, in bytes, qword = int64}): Double; stdcall; External bassdll; // opposite to bass_channelbytes2seconds, bass_channelseconds2bytes can obtain the stream pointer position through time. function bass_channelseconds2bytes (handle: DWORD; pos: Double): qword; stdcall; External bassdll; // opposite to bass_channelgetposition, bass_channelsetposition can be used to set the stream pointer position. function bass_channelsetposition (handle: DWORD; pos: qword; Mode: DWORD): bool; stdcall; External bassdll;
  
   
 
// The total time for obtaining music can be: bass_channelbytes2seconds (HS, bass_channelgetlength (HS, bass_pos_byte); // The current time for obtaining music playback can be: Upper (HS, bass_channelgetposition (HS, HS, bass_pos_byte ));

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, classes, extctrls; Type tform1 = Class (tform) opendialog1: topendialog; timer1: ttimer; button1: tbutton; button2: tbutton; button3: tbutton; weight: weight; Procedure handle (Sender: tobject); Procedure button2click (Sender: tobject); proce Dure button3click (Sender: tobject); Procedure handle (Sender: tobject; scrollcode: tscrollcode; var scrollpos: integer); Procedure formdestroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses bass; var HS: hstream; {stream handle} Time: Double; {total music time} procedure tform1.formcreate (Sender: tobject); begin timer1.interval: = 100; timer1.enabled: = False; scrollbar1.enabled: = false; 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); timer1.enabled: = false; scrollbar1.enabled: = false; opendigalo1.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); if hs

Form file:

Object form1: tform1 left = 205 Top = 107 caption = 'form1' clientheight = 88 clientwidth = 393 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesigned oncreate = formcreate ondestroy = formdestroy pixelsperinch = 96 textheight = 13 object button1: tbutton left = 65 Top = 17 width = 75 Height = 25 caption = #25171 #24320 taborder = 0 onclick = button1click end object button2: tbutton left = 161 Top = 17 width = 75 Height = 25 caption = #25773 #25918 taborder = 1 onclick = button2click end object button3: tbutton left = 257 Top = 17 width = 75 Height = 25 caption = #26242 #20572 taborder = 2 onclick = button3click end object scrollbar1: tscrollbar left = 8 Top = 56 width = 377 Height = 17 pagesize = 0 taborder = 3 onscroll = scrollbar1scroll end object opendialog1: topendialog left = 40 top = 40 end object timer1: ttimer ontimer = timer1timer left = 80 top = 48 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.