2016-03-31 18 views
3

Ses oynatıcısını kullanarak .wav dosyasını çalıştıran bir uygulamaya sahibim, baktım ve oynadığı sesi değiştirmenin bir yolunu bulamadım. Dosyanın hacmini program aracılığıyla bağımsız olarak değiştirmek veya pencerenin hacmini pencere ses mikseri içinde değiştirmek için kaydırıcıya sahip olmak. Teşekkürler!C# windows formları oluşturur uygulama birimi kaydırıcısı

public void loadSound() 
{ 
    sp.Load(); 
    sp.Play(); 
} 

private void timer1_Tick(object sender, EventArgs e) 
{  
    if (BarTimer.Value < BarTimer.Maximum) 
    { 
     BarTimer.Value = BarTimer.Value + 1; 
    } 

    if(BarTimer.Value==BarTimer.Maximum) 
    { 
     loadSound(); 
     timer1.Stop(); 
     BarTimer.Value = BarTimer.Minimum; 
    } 
} 
+1

Wav dosyasını hangi araçlarla oynuyorsunuz? Lütfen kodunuzu gönderin. – auburg

+0

Sp nedir? Hangi medya API'sını kullanıyorsunuz? – auburg

+0

system.media kullanıyorum; – dvs

cevap

4

Yalnızca MSDN'de bulamıyorum: Attenuating SoundPlayer Volume.

waveOutGetVolume ve waveOutSetVolume işlevlerini kullanır.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

namespace VolumeControl 
{ 
    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() 
     { 
     InitializeComponent(); 
     // By the default set the volume to 0 
     uint CurrVol = 0; 
     // At this point, CurrVol gets assigned the volume 
     waveOutGetVolume(IntPtr.Zero, out CurrVol); 
     // Calculate the volume 
     ushort CalcVol = (ushort)(CurrVol & 0x0000ffff); 
     // Get the volume on a scale of 1 to 10 (to fit the trackbar) 
     trackWave.Value = CalcVol/(ushort.MaxValue/10); 
     } 

     private void trackWave_Scroll(object sender, EventArgs e) 
     { 
     // Calculate the volume that's being set. BTW: this is a trackbar! 
     int NewVolume = ((ushort.MaxValue/10) * trackWave.Value); 
     // Set the same volume for both the left and the right channels 
     uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16)); 
     // Set the volume 
     waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels); 
     } 
    } 
} 

Yardım edin.

+1

Buna baktım, dll'leri nasıl ithal edeceğime gerçekten emin değilim, ama ona bir bakacağım, teşekkürler! – dvs

+1

Cevabınızı kod içerecek şekilde düzenledim. +1 –

İlgili konular