Autor Beitrag
Barzi
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 04.06.06 11:22 
Moin, Ich bin dabei einen MediaPlayer zu programmieren. Nun habe ich folgene Frage:
Was für ein Befehl muss ich verwenden um die Lautstärke einzustellen?


Zuletzt bearbeitet von Barzi am So 04.06.06 11:43, insgesamt 1-mal bearbeitet
Hack Gott
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 409

Windows Vista
Delphi 2005 Personal, Delphi 7
BeitragVerfasst: So 04.06.06 12:10 
Ich glaube das du das nicht mit dem Komponenten TMediaPlayer realisieren kannst, ich denke es ist am besten wenn du die Lautstärke Global änderst. Dazu verwendest du einfach folgenden Code:
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:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
{ Frei nach by Serhiy Perevoznyk }  
unit Volume;  

 
interface  
Uses SysUtils, Windows, MMSystem;  

 
////////////////////////////////////////////////////////////////////////////////  
function SetMasterVolume(Value: Cardinal) : boolean;  
function GetMasterVolume : Cardinal;  
////////////////////////////////////////////////////////////////////////////////  
implementation  
////////////////////////////////////////////////////////////////////////////////  
function InitMixer: HMixer;  
var   
  Err: MMRESULT;   
begin   
  Err := mixerOpen(@Result, 0000);  
  if Err <> MMSYSERR_NOERROR then   
    Result := 0;   
end;  
////////////////////////////////////////////////////////////////////////////////  
function GetMasterVolumeControl(Mixer: hMixerObj;  
                                var Control: TMixerControl): MMResult;   
var   
  Line     : TMixerLine;   
  Controls : TMixerLineControls;   
begin   
  ZeroMemory(@Line, SizeOf(Line));  
  Line.cbStruct := SizeOf(Line);   
  Line.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;   
  Result := mixerGetLineInfo(Mixer,   
                             @Line,   
                             MIXER_GETLINEINFOF_COMPONENTTYPE);   
  if Result = MMSYSERR_NOERROR then begin   
    ZeroMemory(@Controls, SizeOf(Controls));   
    Controls.cbStruct := SizeOf(Controls);   
    Controls.dwLineID := Line.dwLineID;   
    Controls.cControls := 1;   
    Controls.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;   
    Controls.cbmxctrl := SizeOf(Control);   
    Controls.pamxctrl := @Control;   
    Result := mixerGetLineControls(Mixer,   
                                   @Controls,   
                                   MIXER_GETLINECONTROLSF_ONEBYTYPE);   
  end;   
end;   
////////////////////////////////////////////////////////////////////////////////  
function SetMasterVolume(Value: Cardinal) : boolean;  
var   
  MasterVolume    : TMixerControl;   
  Details         : TMixerControlDetails;   
  UnsignedDetails : TMixerControlDetailsUnsigned;   
  Code            : MMResult;   
  Mixer           : hMixerObj;   
begin   
  Mixer := InitMixer;   
  Result := false;   
  Code := GetMasterVolumeControl(Mixer, MasterVolume);   
  if(Code = MMSYSERR_NOERROR)then begin   
    with Details do begin   
      cbStruct := SizeOf(Details);   
      dwControlID := MasterVolume.dwControlID;   
      cChannels := 1;  // set all channels   
      cMultipleItems := 0;   
      cbDetails := SizeOf(UnsignedDetails);   
      paDetails := @UnsignedDetails;   
    end;   
    UnsignedDetails.dwValue := Value;   
    if(mixerSetControlDetails(Mixer,   
                              @Details,  
                              MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then   
      Result := true;   
  end;   
end;   
////////////////////////////////////////////////////////////////////////////////  
function GetMasterVolume : Cardinal;  
var  
  MasterVolume    : TMixerControl;   
  Details         : TMixerControlDetails;   
  UnsignedDetails : TMixerControlDetailsUnsigned;   
  Code            : MMResult;   
  Mixer           : hMixerObj;  
begin   
  Mixer := InitMixer;   
  Result := 0;   
  Code := GetMasterVolumeControl(Mixer, MasterVolume);   
  if(Code = MMSYSERR_NOERROR)then begin   
    with Details do begin   
      cbStruct := SizeOf(Details);   
      dwControlID := MasterVolume.dwControlID;   
      cChannels := 1;  // set all channels   
      cMultipleItems := 0;   
      cbDetails := SizeOf(UnsignedDetails);   
      paDetails := @UnsignedDetails;   
    end;   
    if(mixerGetControlDetails(Mixer,   
                              @Details,   
                              MIXER_GETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then  
      result := UnsignedDetails.dwValue;  
  end;  
end;   
////////////////////////////////////////////////////////////////////////////////  
function GetMasterMute(   
  Mixer: hMixerObj;   
  var Control: TMixerControl): MMResult;   
  // Returns True on success   
var   
  Line: TMixerLine;   
  Controls: TMixerLineControls;   
begin   
  ZeroMemory(@Line, SizeOf(Line));   
  Line.cbStruct := SizeOf(Line);   
  Line.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;   
  Result := mixerGetLineInfo(Mixer, @Line,   
    MIXER_GETLINEINFOF_COMPONENTTYPE);   
  if Result = MMSYSERR_NOERROR then   
  begin   
    ZeroMemory(@Controls, SizeOf(Controls));   
    Controls.cbStruct := SizeOf(Controls);   
    Controls.dwLineID := Line.dwLineID;   
    Controls.cControls := 1;   
    Controls.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;   
    Controls.cbmxctrl := SizeOf(Control);   
    Controls.pamxctrl := @Control;   
    Result := mixerGetLineControls(Mixer, @Controls,   
      MIXER_GETLINECONTROLSF_ONEBYTYPE);   
  end;   
end;   
////////////////////////////////////////////////////////////////////////////////  
function MuteMaster : boolean;   
var   
  MasterMute: TMixerControl;   
  Details: TMixerControlDetails;   
  BoolDetails: TMixerControlDetailsBoolean;   
  Code: MMResult;   
begin   
  result := false;   
  Code := GetMasterMute(0, MasterMute);   
  if(Code = MMSYSERR_NOERROR)then   
  begin   
    with Details do   
    begin   
      cbStruct := SizeOf(Details);   
      dwControlID := MasterMute.dwControlID;   
      cChannels := 1;   
      cMultipleItems := 0;   
      cbDetails := SizeOf(BoolDetails);   
      paDetails := @BoolDetails;   
    end;   
    mixerGetControlDetails(0, @Details,   
      MIXER_GETCONTROLDETAILSF_VALUE);   

 
    LongBool(BoolDetails.fValue) := not LongBool(BoolDetails.fValue);  
      
    if(mixerSetControlDetails(0, @Details,   
         MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR)then   
      result := true;        
  end;   
end;  
////////////////////////////////////////////////////////////////////////////////  
end.
Barzi
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 04.06.06 12:20 
Wow, ziemlich langer und komplexer Code. Die Borland-Programmierer dürfen sich ruhig was einfacheres einfallen lassen. Hat aber trotzdem geklappt, DANKE
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 04.06.06 12:29 
Wenn du einen Mediaplayer programmieren willst, dann wäre es ggf. sinnvoll, sich nach anderen Komponenten umzuschauen.
Besonders für die Wiedergabe und Visualisierung von Musik gibt es bessere Möglichkeiten als den TMediaplayer - z.B. "Bass" oder "Fmod". Damit kann man auch einfach mehrere Sachen gleichzeitig abspielen, die Stücke ineinander faden und vor allem die Lautstärke ändern, ohne das direkt global zu tun.

Wie es mit Videos aussieht, kann ich nicht sagen.

_________________
We are, we were and will not be.
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 13:00 
wenn ich zu der verstellung der laustärke eine treckbar benutze, wo muss ich da was am code verändern?
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 15:33 
ok, dann anders: ist es überhaupt möglich eine treckbar dafür zu verwenden?
Ich finde darin nicht, was ähnlichkeit damit hat..
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 25.03.07 15:40 
In einer Trackbar kann man Integer-Werte einstellen. Diese kann man dann einer Prozedur übergeben, die die Lautstärke auf diesen Wert setzt.

D.h. Die SetMasterVolume-Routine musst du mit Trackbar1.Position aufrufen. Wie die Werte skaliert sind (d.h. welcher Wert steht für "maximale Lautstärke"), weiß ich nicht.

_________________
We are, we were and will not be.
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 15:58 
Das heißt, ich muss alle SetMasterVolume-Routine zu Treckbar1.position umschreiben?
Ich finde aber keine SetMasterVolume-Routine, bzw nur SetMasterVolume, wo ich aber nicht anzufangen weiß
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 25.03.07 16:03 
user profile iconRaezor hat folgendes geschrieben:
Ich finde aber keine SetMasterVolume-Routine, bzw nur SetMasterVolume, wo ich aber nicht anzufangen weiß
Den Thread hier hast du aber schon gelesen, oder? :roll: SetMasterVolume erwartet einen Parameter. Einen Cardinal, das ist ein Ganzzahl-Typ (positiv). Trackbar.Position sind ganze Zahlen. Um die Lautsärke zu setzen, könnte man ja mal SetMasterVolume(Trackbar1.Position); probieren und schauen, was passiert.

_________________
We are, we were and will not be.
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: So 25.03.07 16:12 
Noch als Anmerkung, Trackbar1.Maximum sollte 65535 sein, das ist die volle Lautstärke

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 25.03.07 17:13 
Titel: Windows-Lautstärkeregler
Schau mal hier - meine Antwort:

www.delphi-forum.de/...4&highlight=midi
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 17:45 
Hm..naja
Gibt es auch einen SEHR kurzen quellentext zur lautstärkeregelung, weil ich nicht mehr durchsehe^^
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: So 25.03.07 18:35 
Hi,
schau dir den Code an und Frag, wenn du an bestimmten Stellen nicht weiter kommst. Dann lager den Code in eine Unit aus, damit du nicht so viel Code in der Hauptunit hast, der dich nervt und grif auf die Rotinen zu. ;) So lernt man das. Oder nutze eine fertige Komponente, da musst du dich aber auch einarbeiten. :roll:

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 20:55 
ok.
ich mach ein neuen frame und kopiere das komplette zeug da rein.
nun will ich auf die neue unit eine trachbar setzen und es kommt:
Fehler im Modul Unit2. Dekleration der klasse tForm2 fehlt oder ist fehlerhaft.

Sozusagen weiß ich nicht, wo das einzelne hin muss, weil ich zu den standard units kein zusammenhang sehe
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 26.03.07 17:05 
Wie oft soll man dich eigentlich noch auf Einsteigertutorials hinweisen? Es ist doch nichts schlimmes Anfänger zu sein...es ist nur schlimm nichts lernen zu wollen ;)

Seh doch endlich ein das es auf kurz oder lang nur zu deinem eigenem Vorteil ist! Wegen jedem Miniproblem im Forum zu fragen kann doch nicht in deinem Interesse sein!

Kopiere den Quellcode in eine txt-Datei, nenne sie Volume.pas, verschiebe sie in den Lib ordner des Delphi-Verzeichnis. Füge in Unit 1 oder wo auch immer du willst in die Uses-Klausel "Volume" ein.

Dann kannste auf die Funktionen zugreifen als stünden sie in deiner Unit.

z.B. mit SetMasterVolume(2000);