Autor Beitrag
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Do 05.05.05 19:40 
Hi!
Ich verwende die Bass.dll und würde gerne die Tracklänge und Position von Bass- Music (gemeint HMusic, also mod, mo3, ...-Datein). in Sekunden rausfinden. Ne Idee?
THX!

_________________
Programmers never die, they just GOSUB without RETURN
LH_Freak
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 385

Win XP
D7 PE, D2k5 Trial
BeitragVerfasst: So 08.05.05 17:58 
user profile iconalias5000 hat folgendes geschrieben:
Hi!
Ich verwende die Bass.dll und würde gerne die Tracklänge und Position von Bass- Music (gemeint HMusic, also mod, mo3, ...-Datein). in Sekunden rausfinden. Ne Idee?
THX!


Länge: BASS_MusicGetLength
Position: BASS_ChannelGetPosition
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Fr 28.10.05 08:52 
kann mir das einermal genauer erklären ich komme damit gar nicht klar woher weiß er zum Beispiel das er auf die DLL zugreift? oder wie sage ich ihm das.
Wishmaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Sa 29.10.05 05:17 
Wen du bass v2.2 benutzt dann kannst du folgend Code benutzen (aus meinem eigenen Project.)

Bass v2.2
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
//*****************************************************
{-------------------------------- Song Length ---------------------------------}

function TAudioEngine.Get_SongLength: QWORD;
var SongLength: float;
    MilliSec : QWORD;
begin
    SongLength:= BASS_ChannelBytes2Seconds(Channel_Song, BASS_ChannelGetLength(Channel_Song));
    MilliSec := Trunc(1000 * SongLength);
 if MilliSec < 0 then
    MilliSec:= 0;
    Result:= MilliSec;
end;


{----------------------------- Set|Get Position -------------------------------}


Procedure TAudioEngine.Set_SongPosition(Value : QWORD);
var Pos: int64;
Begin
 if (BASS_ChannelIsActive(Channel_Song) <> BASS_ACTIVE_STOPPED) then
  begin
   Pos:= BASS_ChannelSeconds2Bytes(Channel_Song, Value / 1000);
   BASS_ChannelSetPosition(Channel_Song, Pos)
  end;
end;


function TAudioEngine.Get_SongPosition : QWORD;
var Pos  : QWORD;
    FloatPos : FLOAT;
begin
 if (BASS_ChannelIsActive(Channel_Song) <> BASS_ACTIVE_STOPPED) then
  begin
     Pos := BASS_ChannelGetPosition(Channel_Song);
  if Pos < 0 then Pos:= 0;
     FloatPos:= BASS_ChannelBytes2Seconds(Channel_Song, Pos);
     Result:= round(1000 * FloatPos);  //sec -> milli sec
  end
 else
   result:= 0
end;

// Example
// Set_SongPosition(trunc(Get_SongLength * Slider.Position / Slider.Max + 0.1));
// Slider.Position:= trunc((Slider.Max / Get_SongLength) * Get_SongPosition + 0.1)

//*****************************************************
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Fr 06.01.06 11:17 
Danke nochmal hab es erst jetzt bemerkt das du da zurück geschrieben hast hab es auch hin bekommen das er die Funktionen findet aber ich kann mir mit dieser "Cardinal" irgend wie nix vorstellenw a sich dem da über gebe der muss ja irgend wo auch die MP3 wissen oder nicht?

Okay oder noch anders der verlangt ein handel und das soll cardinal sein aber was soll ich dem da zuweisen? denn Mediaplayer oder einen Pfad ich verstehe das absolut nett!
Wishmaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Sa 07.01.06 05:30 
Hi

(Cardinal = DWORD)

Channel : DWORD; // or
Channel : HCHANNEL;

oder in bass.pas

{ HCHANNEL = DWORD; // playing sample's channel handle
HSTREAM = DWORD; } // sample stream handle


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
unit AudioEngine;

interface

uses
 bass, …, ….;

Private
   Channel    :   DWORD;  // or HCHANNEL or HSTREAM



  var
   AudioPlayer : TAudioEngine;


Implementation


procedure TAudioEngine.Load_File(FileName : String); 
begin

   BASS_StreamFree(Channel);
   BASS_MusicFree(Channel);


    Channel:=   (BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0, 0));
if (Channel = 0) then
    Channel:= (BASS_MusicLoad(FALSE, PChar(FileName), 0, 0, 0, 0));


  BASS_ChannelPlay(Channel, false);
end;


{----------------------------- Set|Get Position -------------------------------}

Procedure TAudioEngine.Set_SongPosition(Value : QWORD);
var Pos: QWORD;
Begin
 if (BASS_ChannelIsActive(Channel) <> BASS_ACTIVE_STOPPED) then
  begin
   Pos:= BASS_ChannelSeconds2Bytes(Channel, Value / 1000);
   BASS_ChannelSetPosition(Channel, Pos)
  end;
end;


function TAudioEngine.Get_SongPosition : QWORD;
var Pos  : QWORD;
    FloatPos : FLOAT;
begin
 if (BASS_ChannelIsActive(Channel) <> BASS_ACTIVE_STOPPED) then
  begin
     Pos := BASS_ChannelGetPosition(Channel);
  if Pos < 0 then Pos:= 0;
     FloatPos:= BASS_ChannelBytes2Seconds(Channel, Pos);
     Result:= round(1000 * FloatPos);  //sec -> milli sec
   end
 else
   result:= 0
end;

{------------------------------- Get File Length ------------------------------}

function TAudioEngine.Get_FileLenght : QWORD;
var TotalLen : QWORD;
begin
     TotalLen:=  Bass_StreamGetFilePosition(Channel,  BASS_FILEPOS_END);
 if (BASS_ChannelIsActive(Channel) <> BASS_ACTIVE_STOPPED) then
    result:= TotalLen
  else
    result:= 0;
end;




// Example 1
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
  private
    { Private declarations }
    Scroling : boolean;


procedure TMain_Form.Slider_TimerTimer(Sender: TObject);
begin
 With AudioPlayer do
 begin
  if Get_SongLength > 1 then
   if Scroling = false then
     slider.Position:= trunc((slider.Max / Get_SongLength) *  Get_SongPosition + 0.1)
   else
  else 
     slider.Position:= 0;
  end;
end;

procedure TMain_Form.SliderMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Scroling:= true;
end;

procedure TMain_Form.SliderMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 With AudioPlayer do
  begin
    Scroling:=  false;
    Set_SongPosition(trunc(Get_SongLength * Slider.Position / Slider.Max + 0.1));
 end;
end;


// Example 2
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function  DurationMinSec(Secunden : string) : string;
var Min, Sec : integer;
    SecToTime : string;
begin
   Min:=   StrToInt(Secunden) div 60;
   Sec:=   StrToInt(Secunden) - Min * 60;
   SecToTime:= Format('%2d:%.2d', [Min, Sec]);
   result:=  SecToTime;
end;

  with AudioPlayer do
   begin
     CurTime_lab.Caption:= DurationMinSec(inttostr(trunc(Get_SongPosition/ 1000)));
     TotalTime_lab.Caption:= DurationMinSec(inttostr(trunc(Get_SongLength /1000)));



Ich hoffe ich konnte der weiterhelfen
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 09.01.06 20:48 
hab schon wieder einen denk fehler brauch ich noch irgend eine komponente oder warum bringt der mir denn Fehler

[Fehler] AudioEngine.pas(20): Undefinierter Bezeichner: 'TAudioEngine'

das ist doch eigentlich die neue Unit die ich jetzt erstellt ahbe oder etwa nicht?
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 09.01.06 21:26 
Also zwischendurch nochmal danke an Wishmaster. Ich hab mir davor auch schon die Bass 2.2 runtergeladen und dass dann im Changelog gesehen. Allerdings hab ich mein Projekt noch nicht auf die neue Bass umgestellt, kommt noch.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Wishmaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Di 17.01.06 02:37 
Hi

@Beutel

Nein du brauchst keine Komponente. Du musst nur AudioEngine einbinden



ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
unit AudioEngine;

interface

uses Bass, BASS_AC3, BASS_AAC, …

type
   TAudioEngine = class(TObject)
  Private

  public
   Constructor Create(HWND : THandle); virtual;
   Destructor Destroy;  virtual;
end;

var
   AudioPlayer : TAudioEngine;

Implementation


Constructor TAudioEngine.Create(HWND : THandle);
Begin

  Init_AudioEngine(-1, 44100, 0)
End;


Destructor TAudioEngine.Destroy;
begin
  BASS_Free;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Unit Main_unit

interface

uses AudioEngine, .., ..

type
  TMain_Form = class(TForm)
Private

Public

end

procedure TMain_Form.FormCreate(Sender: TObject);
begin
 AudioPlayer:=  TAudioEngine.Create(Application.Handle);  
End