⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.pas

📁 一个非常好用的MP3音乐播放控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
begin
  VolumeForm.Show;
end;

procedure TPlayerForm.PlayButtonClick(Sender: TObject);
begin
  XaudioPlayer.Play;
end;

procedure TPlayerForm.PauseButtonClick(Sender: TObject);
begin
  XaudioPlayer.Pause
end;

procedure TPlayerForm.StopButtonClick(Sender: TObject);
begin
  XaudioPlayer.Stop;
end;

procedure TPlayerForm.MainMenu_Windows_ShowInfoClick(Sender: TObject);
begin
  InfoForm.Show;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputState(Sender: TXaudioPlayer;
  State: Integer);
begin
  if (state = XA_OUTPUT_STATE_OPEN) then
    VolumeForm.Enabled := True
  else
    VolumeForm.Enabled := False;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputVolume(Sender: TXaudioPlayer;
  MasterLevel, PcmLevel, Balance: Byte);
begin
  VolumeForm.MasterTrackBar.Position := MasterLevel;
  VolumeForm.PcmTrackBar.Position := PcmLevel;
  VolumeForm.BalanceTrackBar.Position := Balance;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputPcmLevel(
  Sender: TXaudioPlayer; PcmLevel: Byte);
begin
  VolumeForm.PcmTrackBar.Position := PcmLevel;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputMasterLevel(
  Sender: TXaudioPlayer; MasterLevel: Byte);
begin
  VolumeForm.MasterTrackBar.Position := MasterLevel;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputBalance(
  Sender: TXaudioPlayer; Balance: Byte);
begin
  VolumeForm.BalanceTrackBar.Position := Balance;
end;

procedure TPlayerForm.MainMenu_Windows_EqualizerClick(Sender: TObject);
begin
    EqualizerForm.Show;
end;

procedure TPlayerForm.XaudioPlayerNotifyPlayerState(Sender: TXaudioPlayer;
  State: Integer);
begin
  case State of
    XA_PLAYER_STATE_STOPPED:
      begin
        StatusBar.Panels[1].Text := 'STOPPED';
        XaudioPlayer.InputSeek(0, 1);
      end;
    XA_PLAYER_STATE_PLAYING:
      StatusBar.Panels[1].Text := 'PLAYING';
    XA_PLAYER_STATE_PAUSED:
      StatusBar.Panels[1].Text := 'PAUSED';
    XA_PLAYER_STATE_EOF:
      begin
        { if we had a playlist, now would be the time to tell }
        { the player to open the next item in the list by     }
        { calling InputOpen() with the next name. This would  }
        { give a perfect queuing effect (no gap between songs)}
        { Since we do not have a playlist, we'll just rewind  }
        { the stream to the beginning.                        }
        StatusBar.Panels[1].Text := 'EOF';
        XaudioPlayer.InputSeek(0,1);
      end;
  end;
end;

procedure TPlayerForm.XaudioPlayerNotifyReady(Sender: TObject);
begin
  Tracking := False;
end;

procedure TPlayerForm.XaudioPlayerNotifyInputModule(Sender: TXaudioPlayer;
  ID: SmallInt);
begin
  if ID <> -1 then
    InfoForm.InputModuleText.Caption := IntToStr(ID)
  else
    InfoForm.InputModuleText.Caption := 'AUTOSELECT';
end;

procedure TPlayerForm.XaudioPlayerNotifyInputName(Sender: TXaudioPlayer;
  const Name: String);
begin
  InputNameText.Caption := Name;
  InfoForm.InputNameText.Caption := Name;
end;

procedure TPlayerForm.XaudioPlayerNotifyInputModuleInfo(
  Sender: TXaudioPlayer; ID, NbDevices: Byte; const Name,
  Description: String);
begin
  ModulesForm.Show;
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyInputDeviceInfo(
  Sender: TXaudioPlayer; ModuleID, Index, Flags: Byte; const Name,
  Description: String);
begin
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0].Item[ModuleID],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputModule(Sender: TXaudioPlayer;
  ID: SmallInt);
begin
    if ID <> -1 then
      InfoForm.OutputModuleText.Caption := IntToStr(ID)
    else
      InfoForm.OutputModuleText.Caption := 'AUTOSELECT';
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputName(Sender: TXaudioPlayer;
  const Name: String);
begin
  InfoForm.OutputNameText.Caption := Name;
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputModuleInfo(
  Sender: TXaudioPlayer; ID, NbDevices: Byte; const Name,
  Description: String);
begin
  ModulesForm.Show;
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyOutputDeviceInfo(
  Sender: TXaudioPlayer; ModuleID, Index, Flags: Byte; const Name,
  Description: String);
begin
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0].Item[ModuleID],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyCodecModuleInfo(
  Sender: TXaudioPlayer; ID, NbDevices: Byte; const Name,
  Description: String);
begin
  ModulesForm.Show;
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyCodecDeviceInfo(
  Sender: TXaudioPlayer; ModuleID, Index, Flags: Byte; const Name,
  Description: String);
begin
  ModulesForm.TreeView.Items.AddChild(ModulesForm.TreeView.Items[0].Item[ModuleID],
    String(Name) + ' [' + String(Description) + ']');
  ModulesForm.TreeView.Items.Item[0].Expand(True);
end;

procedure TPlayerForm.XaudioPlayerNotifyStreamMimeType(
  Sender: TXaudioPlayer; MimeType: String);
begin
     StreamMimeTypeText.Caption := MimeType;
end;

procedure TPlayerForm.XaudioPlayerNotifyStreamParameters(
  Sender: TXaudioPlayer; Frequency: Cardinal; Bitrate: Smallint;
  NbChannels: Byte);
begin
  StreamParametersText.Caption := IntToStr(Frequency) + ' Hz, ' + IntToStr(NbChannels) + ' Ch, ' + IntToStr(Bitrate) + ' kbps';
end;

procedure TPlayerForm.XaudioPlayerNotifyStreamDuration(
  Sender: TXaudioPlayer; Duration: Cardinal);
var
  Hours: Integer;
  Minutes: Integer;
  Seconds: Integer;
begin
  Hours := Duration div 3600;
  Duration := Duration - 3600*Hours;
  Minutes := Duration div 60;
  Duration := Duration - 60*Minutes;
  Seconds := Duration;
  DurationText.Caption := Format('%.2d:%.2d:%.2d', [Hours, Minutes, Seconds]);
end;

procedure TPlayerForm.XaudioPlayerNotifyStreamProperties(
  Sender: TXaudioPlayer; NbProperties: Cardinal; Properties: PXA_Property);
type
  PropertyArray = array[0..1024] of XA_Property;
  PPropertyArray = ^PropertyArray;
var
  I: Integer;
  PropertyList: PPropertyArray;
begin
  PropertyList := PPropertyArray(Properties);
  StreamPropertiesList.Clear;
  for I := 0 to NbProperties-1 do begin
    if (PropertyList[I].value_type = XA_PROPERTY_TYPE_INTEGER) then
      StreamPropertiesList.Items.Add(PropertyList[I].name + ': ' + IntToStr(PropertyList[I].integer_value))
    else if (PropertyList[I].value_type = XA_PROPERTY_TYPE_STRING) then
      StreamPropertiesList.Items.Add(PropertyList[I].name + ': ' + PropertyList[I].string_value);
    end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -