Lautstärke regler einbauen?

06/24/2012 13:37 kleinkiiko#1
Hay

Wie der titel schon sagt würde ich gerne in meinem Programm ein Lautstärkeregler einbauen nur weiß ich nicht wie :/

Das Programm ist ganz simple aufgebaut einfach ein paar Buttons die Onlineradios abspielen ( Technobase.FM , 1Live ect ).Nun würde ich auch gerne noch ein Lautstärkeregler einbauen.Kann mir bitte jemand ein Tut schicken?Oder Änliches.


MfG Kiko
06/24/2012 14:14 Coding Lounge#2
Du brauchst eine TrackBar und folgenden Code (C#):

Code:
using System.Runtime.InteropServices;

public partial class Form1 : Form
    {
        [DllImport("winmm.dll")]
        public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);

        [DllImport("winmm.dll")]
        public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
		
		
		public Form1()
		{
            uint CurrVol = 0;
            waveOutGetVolume(IntPtr.Zero, out CurrVol);
            ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
            tBarVolume.Value = CalcVol / (ushort.MaxValue / 10);
		}
		
		private void tBarVolume_Scroll(object sender, EventArgs e)
        {
            int NewVolume = ((ushort.MaxValue / 10) * tBarVolume.Value);
            uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
            waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);

        }
	}
06/24/2012 14:45 kleinkiiko#3
Mhmm es geht nicht da kommen 25fehler :/
Ist das für Visual Basic 2010?
Weil ich benutze VB :)
06/24/2012 15:19 Coding Lounge#4
Nö, das ist C#. Hättest du auch sagen können ;)
06/24/2012 15:28 kleinkiiko#5
Ja sorry habe ich vergessen tut mir leid :)
06/24/2012 18:06 Coding Lounge#6
Code:
Imports System.Runtime.InteropServices

Public Partial Class Form1
	Inherits Form
	<DllImport("winmm.dll")> _
	Public Shared Function waveOutGetVolume(hwo As IntPtr, ByRef dwVolume As UInteger) As Integer
	End Function

	<DllImport("winmm.dll")> _
	Public Shared Function waveOutSetVolume(hwo As IntPtr, dwVolume As UInteger) As Integer
	End Function


	Public Sub New()
		Dim CurrVol As UInteger = 0
		waveOutGetVolume(IntPtr.Zero, CurrVol)
		Dim CalcVol As UShort = CUShort(CurrVol And &Hffff)
		tBarVolume.Value = CalcVol \ (UShort.MaxValue \ 10)
	End Sub

	Private Sub tBarVolume_Scroll(sender As Object, e As EventArgs)
		Dim NewVolume As Integer = ((UShort.MaxValue \ 10) * tBarVolume.Value)
		Dim NewVolumeAllChannels As UInteger = ((CUInt(NewVolume) And &Hffff) Or (CUInt(NewVolume) << 16))
		waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels)

	End Sub
End Class
06/25/2012 09:13 boxxiebabee#7
Quote:
Originally Posted by Coding Lounge View Post
Code:
Imports System.Runtime.InteropServices

Public Partial Class Form1
	Inherits Form
	<DllImport("winmm.dll")> _
	Public Shared Function waveOutGetVolume(hwo As IntPtr, ByRef dwVolume As UInteger) As Integer
	End Function

	<DllImport("winmm.dll")> _
	Public Shared Function waveOutSetVolume(hwo As IntPtr, dwVolume As UInteger) As Integer
	End Function


	Public Sub New()
		Dim CurrVol As UInteger = 0
		waveOutGetVolume(IntPtr.Zero, CurrVol)
		Dim CalcVol As UShort = CUShort(CurrVol And &Hffff)
		tBarVolume.Value = CalcVol \ (UShort.MaxValue \ 10)
	End Sub

	Private Sub tBarVolume_Scroll(sender As Object, e As EventArgs)
		Dim NewVolume As Integer = ((UShort.MaxValue \ 10) * tBarVolume.Value)
		Dim NewVolumeAllChannels As UInteger = ((CUInt(NewVolume) And &Hffff) Or (CUInt(NewVolume) << 16))
		waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels)

	End Sub
End Class
Ehm, er verwendet zu 99% sicher nur den Windows Media Player, da gehts um einiges einfacher.
06/25/2012 21:13 'xLeatz.#8
du kannst doch auch ein einfach den Regler vom MediaPlayer Control nehmen.
06/26/2012 14:38 Coding Lounge#9
Quote:
Originally Posted by boxxiebabee View Post
Ehm, er verwendet zu 99% sicher nur den Windows Media Player, da gehts um einiges einfacher.
Les dir bitte doch bevor du postest nochmal den Titel durch.