现在需要用Waveout函数系列来实现播放wav文件的功能,播放功能已经实现,现在实现快进的功能的时候出现了一个问题,就是在按下快进按钮的时候, 原来已经读入缓冲区的音频内容还在, 请问这时候如何去清除缓冲区内的音频内容.
如果你用的是C#就可以用进度条直接拖动,那样最方便。我写的一个播放器,部分代码如下:你可以参考一下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ChatSharpPlayer
{
public partial class ChatSharpPlayer : Form
{
int x,btopmost;
public ChatSharpPlayer()
{
btopmost = 1;
InitializeComponent();
}
private void 电影一ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Player1.URL = openFileDialog1.FileName;
string temp = researchTheFileName(openFileDialog1.FileName);
listBox1.Items.Add(temp);
}
timer1.Enabled = true;
x = 1;
}
private void 电影二ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Player2.URL = openFileDialog1.FileName;
string temp = researchTheFileName(openFileDialog1.FileName);
listBox1.Items.Add(temp);
}
timer1.Enabled = true;
x = 2;
}
private void 电影三ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Player3.URL = openFileDialog1.FileName;
string temp = researchTheFileName(openFileDialog1.FileName);
listBox1.Items.Add(temp);
}
timer1.Enabled = true;
x = 3;
}
private void 电影四ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Player4.URL = openFileDialog1.FileName;
string temp = researchTheFileName(openFileDialog1.FileName);
listBox1.Items.Add(temp);
}
timer1.Enabled = true;
x = 4;
}
private void Player1_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e)
{
x = 1;
}
private void Player2_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e)
{
x = 2;
}
private void Player3_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e)
{
x = 3;
}
private void Player4_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e)
{
x = 4;
}
private void button1_Click(object sender, EventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.play(); break;
case 2: Player2.Ctlcontrols.play(); break;
case 3: Player3.Ctlcontrols.play(); break;
case 4: Player4.Ctlcontrols.play(); break;
}
}
private void button2_Click(object sender, EventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.pause(); break;
case 2: Player2.Ctlcontrols.pause(); break;
case 3: Player3.Ctlcontrols.pause(); break;
case 4: Player4.Ctlcontrols.pause(); break;
}
}
private void button3_Click(object sender, EventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.stop(); break;
case 2: Player2.Ctlcontrols.stop(); break;
case 3: Player3.Ctlcontrols.stop(); break;
case 4: Player4.Ctlcontrols.stop(); break;
}
}
private void button4_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.currentPosition = trackBar1.Value;
Player1.Ctlcontrols.play(); break;
case 2: Player2.Ctlcontrols.currentPosition = trackBar1.Value;
Player2.Ctlcontrols.play(); break;
case 3: Player3.Ctlcontrols.currentPosition = trackBar1.Value;
Player3.Ctlcontrols.play(); break;
case 4: Player4.Ctlcontrols.currentPosition = trackBar1.Value;
Player4.Ctlcontrols.play(); break;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
switch (x)
{
case 1:trackBar1.Maximum = (int)Player1.currentMedia.duration;
trackBar1.Value = (int)Player1.Ctlcontrols.currentPosition; break;
case 2:trackBar1.Maximum = (int)Player2.currentMedia.duration;
trackBar1.Value = (int)Player2.Ctlcontrols.currentPosition; break;
case 3:trackBar1.Maximum = (int)Player3.currentMedia.duration;
trackBar1.Value = (int)Player3.Ctlcontrols.currentPosition; break;
case 4:trackBar1.Maximum = (int)Player4.currentMedia.duration;
trackBar1.Value = (int)Player4.Ctlcontrols.currentPosition; break;
}
}
private void trackBar1_MouseUp(object sender, MouseEventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.play(); break;
case 2: Player2.Ctlcontrols.play(); break;
case 3: Player3.Ctlcontrols.play(); break;
case 4: Player4.Ctlcontrols.play(); break;
}
}
private void trackBar1_MouseDown(object sender, MouseEventArgs e)
{
switch (x)
{
case 1: Player1.Ctlcontrols.pause(); break;
case 2: Player2.Ctlcontrols.pause(); break;
case 3: Player3.Ctlcontrols.pause(); break;
case 4: Player4.Ctlcontrols.pause(); break;
}
}
private void trackBar2_Scroll(object sender, EventArgs e)
{
switch (x)
{
case 1: Player1.settings.volume = trackBar2.Value; break;
case 2: Player2.settings.volume = trackBar2.Value; break;
case 3: Player3.settings.volume = trackBar2.Value; break;
case 4: Player4.settings.volume = trackBar2.Value; break;
}
}
private void button5_Click(object sender, EventArgs e)
{
btopmost++;
if (btopmost % 2 == 0)
{
this.TopMost = false;
button5.Text = "置前";
}
else
{
this.TopMost = true;
button5.Text = "取消置前";
}
}
private string researchTheFileName(string m)
{
char[] fg={'\\'};
string[] FileName = m.Split(fg);
int i = FileName.Length - 1;
return FileName;
}
private void button6_Click(object sender, EventArgs e)
{
Player1.settings.mute = !(Player1.settings.mute);
}
}
}
可以实现:进度条拖动,静音,音量调节,窗口置前,可以同时播放四个视频。
buffer自己是可以访问得到的。至于你的快进应该是把播放速度放快的就行了,要是拖动到一个位置播放,那要waveOutUnprepareHeader,然后waveOutPrepareHeader 来重新设置buffer