我正在制作一个简单的媒体播放器,我想添加一些常规功能,如轨迹栏控件,它们在运行时与视频/音乐同步。
这是我到目前为止所做的:
namespace Joe_Media_Player
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pausebutton_Click(object sender, EventArgs e)
{
if(axWindowsMediaPlayer1.playState == WMPPlayState.wmppsPaused)
{
mediaplayer.Ctlcontrols.play();
}
else
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
}
private void playbutton_Click(object sender, EventArgs e)
{
listBox1.SelectedIndex = 0;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void BrowseBtn_Click(object sender, EventArgs e) // Open file //
{
using (OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true, ValidateNames = true, Filter = "(mp3,wav,wav,mov,wmv,mpg,avi,3gp,flv|*.mp3;*.mp4;*.wav;*.mov;*.wmv;*.mpg;*.avi;*.3gp;*.flv|all files|*.*" }) //HEADER
{
if (ofd.ShowDialog() == DialogResult.OK) // Kondisi mulai
{
List<MediaFile> files = new List<MediaFile>(); // Membuat list baru musik/video
foreach (string fileName in ofd.FileNames) // Cetak file nama
{
FileInfo fi = new FileInfo(fileName); // New file info nama
files.Add(new MediaFile() { FileName = Path.GetFileNameWithoutExtension(fi.FullName), Path = fi.FullName }); // Pilih file musik/video
}
listBox1.DataSource = files; // List data file
listBox1.ValueMember = "Path"; // List tipe
listBox1.DisplayMember = "FileName"; // File nama
}
}
}
private void MinBtn_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Minimized;
}
private void MaxBtn_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
private void rewindbutton_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.fastReverse();
}
private void prevbutton_Click(object sender, EventArgs e)
{
if(axWindowsMediaPlayer1r.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
if(listBox1.SelectedIndex == 0)
{
listBox1.SelectedIndex = 0;
listBox1.Update();
}
else
{
axWindowsMediaPlayer1.Ctlcontrols.previous();
listBox1.SelectedIndex -= 1;
listBox1.Update();
}
}
mediaplayer.Ctlcontrols.previous();
}
private void stopbutton_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
private void nextbutton_Click(object sender, EventArgs e)
{
if(axWindowsMediaPlayer1.playState== WMPLib.WMPPlayState.wmppsPlaying)
{
if(listBox1.SelectedIndex < (listBox1.Items.Count -1))
{
axWindowsMediaPlayer1.Ctlcontrols.next();
listBox1.SelectedIndex += 1;
listBox1.Update();
}
else
{
listBox1.SelectedIndex = 0;
listBox1.Update();
}
}
}
private void fastfowardbutton_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.fastForward();
}
ListBox1中
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MediaFile file = listBox1.SelectedItem as MediaFile;
if (file != null)
{
axWindowsMediaPlayer1.URL = file.Path;// Pilih tipe file
mediaplayer.Ctlcontrols.play(); // Contorl mulai musik/video
}
}
音量轨迹栏
private void volumetrackbar_ValueChanged(object sender, EventArgs e)
{
int rate = 100 * (bunifuSlider2.Value - 10);
axWindowsMediaPlayer1.settings.volume = bunifuSlider2.Value;
}
private void volumebutton_Click(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.settings.volume == 100)
{
axWindowsMediaPlayer1.settings.volume = 0;
bunifuSlider2.Value = 0;
}
else
{
axWindowsMediaPlayer1.settings.volume = 100;
bunifuSlider2.Value = 100;
}
}
trackbar&amp;计时器(现在不是代码)
private void trackbar_ValueChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
我该怎么做?
答案 0 :(得分:0)
private void axWindowsMediaPlayer1_OpenStateChange(object sender, AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e)
{
if (axWindowsMediaPlayer1.openState == WMPLib.WMPOpenState.wmposMediaOpen)
{
trackBar1.Maximum = (int)axWindowsMediaPlayer1.currentMedia.duration;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
trackBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = trackBar1.Value;
}