Playing MP3 with multi-media library bass. dll [10]-using callback function

Source: Internet
Author: User
In this example:


Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, classes, extctrls, comctrls; Type tform1 = Class (tform) opendialog1: topendialog; trackbar1: ttrackbar; timer1: ttimer; button1: tbutton; button2: tbutton; button3: tbutton; procedure invoke (Sender: tobject); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject ); Procedure button3click (Sender: tobject); Procedure formdestroy (Sender: tobject); Procedure timer1timer (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses bass; var HS: hstream; {stream handle} {callback function: mysync1; although no parameters are used, however, procedure mysync1 (handle: hsync; channel, Data, user: DWORD); stdcall; begin form1.text: = 'starts playing '; end; {callback function: mysync2} {parameter 1: callback handle, which can have bass_channelsetsync Return and delete with bass_channelremovesync {parameter 2: stream handle} {parameter 3: Unknown} {parameter 4: user data specified by bass_channelsetsync} procedure mysync2 (handle: hsync; channel, Data, user: DWORD); stdcall; begin form1.text: = 'over midpoint '; {if the stream is played here (in the center), it will be repeated from the beginning. You can do this :} // bass_channelplay (Channel, true); end; {callback function: mysync3; although no parameters are used, you must specify} procedure mysync3 (handle: hsync; channel, Data, user: DWORD); stdcall; begin form1.text: = 'playback completed '; end; {initialization} Procedure destroy (Sender: tobject); begin trackbar1.height: = 23; timer1.enabled: = false; timer1.interval: = 100; 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} procedure upload (Sender: tobject); var mp3path: ansistring; mp3len: Cardinal; begin bass_streamfree (HS); timer1.enabled: = false; 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); if hs

Form file:

object Form1: TForm1  Left = 222  Top = 114  Caption = 'Form1'  ClientHeight = 84  ClientWidth = 254  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 = 8    Top = 18    Width = 75    Height = 25    Caption = #25171#24320    TabOrder = 0    OnClick = Button1Click  end  object Button2: TButton    Left = 89    Top = 18    Width = 75    Height = 25    Caption = #25773#25918    TabOrder = 1    OnClick = Button2Click  end  object Button3: TButton    Left = 170    Top = 18    Width = 75    Height = 25    Caption = #26242#20572    TabOrder = 2    OnClick = Button3Click  end  object TrackBar1: TTrackBar    Left = 1    Top = 53    Width = 250    Height = 28    TabOrder = 3  end  object OpenDialog1: TOpenDialog    Left = 72    Top = 32  end  object Timer1: TTimer    OnTimer = Timer1Timer    Left = 152    Top = 32  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.