Also know as
Messages postés259Date d'inscriptionsamedi 13 décembre 2003StatutMembreDernière intervention22 novembre 2010
-
19 avril 2007 à 17:59
f0xi
Messages postés4205Date d'inscriptionsamedi 16 octobre 2004StatutModérateurDernière intervention12 mars 2022
-
19 avril 2007 à 18:59
Bonjour a tous,
Bon alors apres une longue surune certaine erreur enfin resolu :-), on m'a conseille d'utiliser un nouvel API.
Je souhaiterais utiliser apparemment "Winamp API".
La seule chose que j'ai pu trouver pour delphi c'est cela :
"unit WinampApi;
interface
uses Windows,Messages,Classes,SysUtils;
type
TWinampApi = class
private
WinampHnd : THandle;
function ConvertTime(n: integer;m : integer): string;
function ConvertTimeTool(n: integer): string;
function split(seperator: Char; text: String; var list: TStringList): Integer;
Result := IntToStr(SendMessage(WinampHnd,WM_USER,0,126));
end;
function TWinampApi.getSongBitRate():String;
begin
Result := IntToStr(SendMessage(WinampHnd,WM_USER,1,126));
end;
function TWinampApi.getSongChannels():String;
begin
Result := IntToStr(SendMessage(WinampHnd,WM_USER,2,126));
end;
function TWinampApi.getPlayListPosition():String;
var
TempInt : Integer;
begin
TempInt := SendMessage(WinampHnd,WM_USER,0,125);
if StrToInt(getPlayListLength()) <1 then
Result := IntToStr(TempInt)
else
Result := IntToStr(TempInt +1);
end;
function TWinampApi.getPlayListLength():String;
begin
Result := IntToStr(SendMessage(WinampHnd,WM_USER,0,124));
end;
{ ----- PRIVATE METHODS ----- }
function TWinampApi.ConvertTime(n: integer;m : integer): string;
begin
n := n div m;
result := ConvertTimeTool(n div 60) + \':\' + ConvertTimeTool(n mod 60);
end;
function TWinampApi.ConvertTimeTool(n: integer): string;
begin
if n < 10 then
result := \'0\' + inttostr(n)
else
result := inttostr(n);
end;
function TWinampApi.split(seperator: Char; text: String; var list: TStringList): Integer;
var
mypos, number: Integer;
begin
number:=0;
if Length(text) > 0 then
begin
if text[Length(text)] <> seperator then
text:=text+seperator;
while(Pos(String(seperator),text))>0 do
begin
mypos:=Pos(String(seperator),text);
list.Add(Copy(text,1,mypos-1));
text:=Copy(text,mypos+1,Length(text)-mypos);
Inc(number);
end;
end;
Result:=number;
end;
end."
----------------
N'y connaissan strictement rien en "installation" d'API, pourriez-vous
m'indiquer les demarches a suivre pour pouvoir utiliser autre chose que
ce fameux TMediaPlayer
Les composats API les plus utilises seraient apparemment ceux-la : Bass, FMod, WinAmp API, DSEngine..
function IsPlaying : boolean;
function IsStopped : boolean;
function IsPaused : boolean;
function IsSoundMuted : boolean;
function IsCurrentTrackExists : boolean;
end;
function TimeCode(const M,S : word) : TTimeCode; overload;
function TimeCode(const I : Integer) : TTimeCode; overload;
function TimeCodeToInt(const TC : TTimeCode) : integer;
function TimeCodeToStr(TC : TTimeCode) : string;
implementation
{ ---- }
function Clamp(const V,AMin,AMax : integer) : integer; overload;
begin
if V < AMin then
result := AMin
else
if V > AMax then
result := AMax
else
result := V;
end;
function TimeCode(const M,S : word) : TTimeCode;
begin
result.M := M;
result.S := S;
end;
function TimeCode(const I : Integer) : TTimeCode;
begin
result.M := I div 60;
result.S := I mod 60;
end;
function TimeCodeToInt(const TC : TTimeCode) : integer;
begin
result := (TC.M*60) + TC.S;
end;
function TimeCodeToStr(TC : TTimeCode) : string;
begin
result := format('%.2d:%.2d',[TC.M,TC.S]);
end;
{ ---- }
type
EBASSBADVERSION = class(Exception);
EBASSINITERROR = class(Exception);
{ ---- }
constructor TBassPlayer.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
fBassActive := not (BASS_GetVersion <> DWORD(MAKELONG(2,2)));
if not fBassActive then
begin
Raise EBASSBADVERSION.Create('Ce composant a besoin de l''API BASS v2.2.');
end else
begin
fBassActive := BASS_Init(-1, 48000, BASS_DEVICE_LEAVEVOL, (AOwner as TWinControl).Handle, nil);
if not fBassActive then
Raise EBASSINITERROR.Create('Erreur d''initialisation de l''API BASS.');
end;
end;
procedure TBassPlayer.DoTimer(Sender : TObject);
begin
PlayQuery;
if TimeCodeToInt(fMusicPos) >= TimeCodeToInt(fMusicLength) then
Stop;
end;
procedure TBassPlayer.fSetFiles(Val : TStringList);
begin
fFiles.Assign(val);
end;
procedure TBassPlayer.fSetTrackIndex(Val : integer);
begin
if (Val < 0) or (Val > fFiles.Count-1) then
begin
ErrorQuery(PE_INDEX_OVERLIMITS);
exit;
end;
if (fFiles.Count = 0) then
begin
fTrackIndex := -1;
ErrorQuery(PE_PLAYLIST_IS_EMPTY);
exit;
end;
if (fTrackIndex <> Val) then
begin
fTrackIndex := Val;
end;
end;
function TBassPlayer.fGetTrackIndex : integer;
begin
if fFiles.Count = 0 then
begin
fTrackIndex := -1;
end;
result := fTrackIndex;
end;
function TBassPlayer.fGetTrackName : string;
begin
result := '';
if TrackIndex <> -1 then
result := Files[TrackIndex];
end;
{ ------ }
const
VRatio = 100/32768;
procedure TBassPlayer.PlayQuery;
var VL : DWord;
LL,LR : integer;
begin
if Assigned(fOnPlaying) then
begin
VL := BASS_ChannelGetLevel(fChannel);
LL := clamp(trunc(VRatio * LOWORD(VL)),0,100);
LR := clamp(trunc(VRatio * HIWORD(VL)),0,100);
procedure TBassPlayer.StopQuery;
begin
if Assigned(fOnStop) then
fOnStop(Self);
end;
procedure TBassPlayer.PauseQuery;
begin
if Assigned(fOnPause) then
fOnPause(Self);
end;
procedure TBassPlayer.SoundMuteQuery;
begin
if Assigned(fOnSoundMute) then
fOnSoundMute(Self);
end;
procedure TBassPlayer.ErrorQuery(const ErrorCode : integer);
begin
if Assigned(fOnError) then
fOnError(Self,ErrorCode);
end;
{ ------ }
procedure TBassPlayer.Play;
var FN : string;
TC : integer;
begin
if (not fBassActive) or (TrackIndex = -1) then
begin
ErrorQuery(PE_API_NOT_ACTIVATED);
Exit;
end;
Stop;
if (not IsPlaying) and IsCurrentTrackExists then
begin
FN := fGetTrackName;
fChannel := BASS_StreamCreateFile(False, pchar(FN), 0, 0, BASS_STREAM_PRESCAN);
if fChannel = 0 then
begin
ErrorQuery(PE_CREATE_STREAM_ERROR);
end else
begin
fPlayerStates := fPlayerStates - [psStop,psPause] + [psPlay];
fTimer.Enabled := true;
BASS_ChannelPlay(fChannel,FALSE);
fMusicLength := TimeCode(trunc(BASS_ChannelBytes2Seconds(fChannel,BASS_ChannelGetLength(fChannel))));
end;
end;
end;
procedure TBassPlayer.Stop;
begin
if not fBassActive then
begin
ErrorQuery(PE_API_NOT_ACTIVATED);
Exit;
end;
if not IsStopped then
begin
fPlayerStates := fPlayerStates - [psPlay,psPause] + [psStop];
BASS_ChannelStop(fChannel);
fTimer.Enabled := false;
BASS_StreamFree(fChannel);
fMusicPos := TimeCode(0,0);
fMusicLength := TimeCode(0,0);
if Assigned(fOnPlaying) then
fOnPlaying(Self, fMusicPos, fMusicLength, 0, 0);
StopQuery;
end;
end;
procedure TBassPlayer.Pause;
begin
if not fBassActive then
begin
ErrorQuery(PE_API_NOT_ACTIVATED);
Exit;
end;
if (not IsPaused) and IsPlaying then
begin
fPlayerStates := fPlayerStates + [psPause];
fTimer.Enabled := false;
BASS_ChannelPause(fChannel);
if Assigned(fOnPlaying) then
fOnPlaying(Self, fMusicPos, fMusicLength, 0, 0);
PauseQuery;
end else
if IsPaused and IsPlaying then
begin
fPlayerStates := fPlayerStates - [psPause];
BASS_ChannelPlay(fChannel,false);
fTimer.Enabled := true;
end;
end;
procedure TBassPlayer.SoundMute;
begin
if not fBassActive then
begin
ErrorQuery(PE_API_NOT_ACTIVATED);
Exit;
end;
if IsSoundMuted then
begin
fPlayerStates := fPlayerStates - [psSoundMute];
{ sound mute }
fMuteVolume := BASSAPIV22.BASS_GetVolume;
BASS_SetVolume(0);
SoundMuteQuery;
end else
begin
fPlayerStates := fPlayerStates + [psSoundMute];
BASS_SetVolume(fMuteVolume);
end;
end;
{ ------ }
procedure TBassPlayer.SetVolume(const Vol : cardinal);
begin
if IsSoundMuted then
fMuteVolume := Vol
else
BASS_SetVolume(Vol);
end;
{ ------ }
procedure TBassPlayer.SetMusicPos(const TC : TTimeCode);
begin
SetMusicPos(TimeCodeToInt(TC));
end;
procedure TBassPlayer.SetMusicPos(const TC : integer);
begin
BASS_ChannelSetPosition(fChannel,TC);
end;
{ ------ }
procedure TBassPlayer.NextTrack;
begin
Stop;
TrackIndex := TrackIndex + 1;
if TrackIndex <> -1 then Play;
end;
procedure TBassPlayer.PreviousTrack;
begin
Stop;
TrackIndex := TrackIndex - 1;
if TrackIndex <> -1 then Play;
end;
procedure TBassPlayer.JumpToTrack(const Index : integer);
begin
Stop;
TrackIndex := Index;
if TrackIndex <> -1 then Play;
end;
{ ------ }
function TBassPlayer.IsPlaying : boolean;
begin
result := psPlay in fPlayerStates;
end;
function TBassPlayer.IsStopped : boolean;
begin
result := psStop in fPlayerStates;
end;
function TBassPlayer.IsPaused : boolean;
begin
result := psPause in fPlayerStates;
end;
function TBassPlayer.IsSoundMuted : boolean;
begin
result := psSoundMute in fPlayerStates;
end;
function TBassPlayer.IsCurrentTrackExists : boolean;
begin
result := FileExists(Files[TrackIndex]) and (TrackIndex <> -1);
end;