1、C#播放器以下是全部代码:1.Form1.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Collections;namespace 自制影音播放器 public partial class Form1 : Form public Form1() InitializeComponent(); Arra
2、yList strFilenames = new ArrayList(); /存放完整文件名 private void button1_Click(object sender, EventArgs e) OpenFileDialog openFile = new OpenFileDialog(); openFile.Multiselect = true; DialogResult dr = openFile.ShowDialog(); if (dr = DialogResult.OK) int count = lstFilm.Items.Count;/记录添加前的项数 /取得文件主名并在列表框
3、中显示 foreach (string name in openFile.FileNames) strFilenames.Add(name); lstFilm.Items.Add(System.IO.Path.GetFileNameWithoutExtension(name); /默认播放刚添加的第一个 lstFilm.SelectedIndex = count; private void listBox1_SelectedIndexChanged(object sender, EventArgs e) Player.URL = strFilenameslstFilm.SelectedInde
4、x.ToString(); lblTime.Text = 00:00n + Player.currentMedia.durationString; timer1.Enabled = true; private void button2_Click(object sender, EventArgs e) Player.Ctlcontrols.play(); private void button3_Click(object sender, EventArgs e) Player.Ctlcontrols.pause(); private void button4_Click(object send
5、er, EventArgs e) if (lstFilm.SelectedIndex 0) lstFilm.SelectedIndex -= 1; else lstFilm.SelectedIndex = lstFilm.Items.Count - 1; private void button5_Click(object sender, EventArgs e) if (lstFilm.SelectedIndex 1000) trackProcess.TickFrequency = trackProcess.Maximum / 100; else trackProcess.TickFreque
6、ncy = trackProcess.Maximum / 20; /音量 trackVolume.Maximum = 100; trackVolume.Minimum = 0; trackVolume.TickFrequency = 10; trackVolume.Value = Player.settings.volume; lblTime.Text = 00:00n + Player.currentMedia.durationString; private void trackProcess_Scroll(object sender, EventArgs e) Player.Ctlcont
7、rols.currentPosition = trackProcess.Value; private void trackVolume_Scroll(object sender, EventArgs e) Player.settings.volume = trackVolume.Value; private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) Application.Exit(); private void toolStripMenuItem1_Click(object sender, EventArgs e)
8、 strFilenames.Clear(); lstFilm.Items.Clear(); 2.Program.csusing System;using System.Collections.Generic;using System.Windows.Forms;namespace 自制影音播放器 static class Program / / 应用程序的主入口点。 / STAThread static void Main() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(fals
9、e); Application.Run(new Form1(); 3.Form1.Designer.csnamespace 自制影音播放器 partial class Form1 / / 必需的设计器变量。 / private System.ComponentModel.IContainer components = null; / / 清理所有正在使用的资源。 / / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null)
10、components.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 / private void InitializeComponent() ponents = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourc
11、eManager(typeof(Form1); this.panel1 = new System.Windows.Forms.Panel(); this.splitter1 = new System.Windows.Forms.Splitter(); this.lstFilm = new System.Windows.Forms.ListBox(); this.panel2 = new System.Windows.Forms.Panel(); this.panel4 = new System.Windows.Forms.Panel(); this.trackProcess = new Sys
12、tem.Windows.Forms.TrackBar(); this.lblTime = new System.Windows.Forms.Label(); this.panel3 = new System.Windows.Forms.Panel(); this.panel5 = new System.Windows.Forms.Panel(); this.trackVolume = new System.Windows.Forms.TrackBar(); this.button6 = new System.Windows.Forms.Button(); this.button5 = new
13、System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文件FToolS
14、tripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.打开OToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.退出XToolStripMe
15、nuItem = new System.Windows.Forms.ToolStripMenuItem(); this.timer1 = new System.Windows.Forms.Timer(ponents); this.toolTip1 = new System.Windows.Forms.ToolTip(ponents); this.Player = new AxWMPLib.AxWindowsMediaPlayer(); this.panel1.SuspendLayout(); this.panel2.SuspendLayout(); this.panel4.SuspendLay
16、out(); (System.ComponentModel.ISupportInitialize)(this.trackProcess).BeginInit(); this.panel3.SuspendLayout(); this.panel5.SuspendLayout(); (System.ComponentModel.ISupportInitialize)(this.trackVolume).BeginInit(); this.menuStrip1.SuspendLayout(); (System.ComponentModel.ISupportInitialize)(this.Playe
17、r).BeginInit(); this.SuspendLayout(); / / panel1 / this.panel1.Controls.Add(this.Player); this.panel1.Controls.Add(this.splitter1); this.panel1.Controls.Add(this.lstFilm); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 24); this.panel1.Name
18、 = panel1; this.panel1.Size = new System.Drawing.Size(534, 289); this.panel1.TabIndex = 2; / / splitter1 / this.splitter1.Location = new System.Drawing.Point(131, 0); this.splitter1.Name = splitter1; this.splitter1.Size = new System.Drawing.Size(3, 289); this.splitter1.TabIndex = 5; this.splitter1.T
19、abStop = false; / / lstFilm / this.lstFilm.Dock = System.Windows.Forms.DockStyle.Left; this.lstFilm.FormattingEnabled = true; this.lstFilm.IntegralHeight = false; this.lstFilm.ItemHeight = 12; this.lstFilm.Location = new System.Drawing.Point(0, 0); this.lstFilm.Name = lstFilm; this.lstFilm.Size = ne
20、w System.Drawing.Size(131, 289); this.lstFilm.TabIndex = 4; this.toolTip1.SetToolTip(this.lstFilm, 播放文件列表); this.lstFilm.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); / / panel2 / this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.p
21、anel2.Controls.Add(this.panel4); this.panel2.Controls.Add(this.panel3); this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; this.panel2.Location = new System.Drawing.Point(0, 313); this.panel2.Name = panel2; this.panel2.Size = new System.Drawing.Size(534, 38); this.panel2.TabIndex = 3; / / pan
22、el4 / this.panel4.Controls.Add(this.trackProcess); this.panel4.Controls.Add(this.lblTime); this.panel4.Dock = System.Windows.Forms.DockStyle.Fill; this.panel4.Location = new System.Drawing.Point(297, 0); this.panel4.Name = panel4; this.panel4.Size = new System.Drawing.Size(237, 38); this.panel4.TabI
23、ndex = 1; / / trackProcess / this.trackProcess.AutoSize = false; this.trackProcess.Dock = System.Windows.Forms.DockStyle.Fill; this.trackProcess.Location = new System.Drawing.Point(71, 0); this.trackProcess.Name = trackProcess; this.trackProcess.Size = new System.Drawing.Size(166, 38); this.trackPro
24、cess.TabIndex = 0; this.toolTip1.SetToolTip(this.trackProcess, 播放进度,可以通过拖动滑块进行调节); this.trackProcess.Scroll += new System.EventHandler(this.trackProcess_Scroll); / / lblTime / this.lblTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lblTime.Dock = System.Windows.Forms.DockStyle.
25、Left; this.lblTime.Font = new System.Drawing.Font(宋体, 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)(134); this.lblTime.Location = new System.Drawing.Point(0, 0); this.lblTime.Name = lblTime; this.lblTime.Size = new System.Drawing.Size(71, 38); this.lblTime.TabInd
26、ex = 1; this.lblTime.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.toolTip1.SetToolTip(this.lblTime, 已播放时间/总时间); / / panel3 / this.panel3.Controls.Add(this.panel5); this.panel3.Controls.Add(this.button6); this.panel3.Controls.Add(this.button5); this.panel3.Controls.Add(this.button4)
27、; this.panel3.Controls.Add(this.button3); this.panel3.Controls.Add(this.button2); this.panel3.Controls.Add(this.button1); this.panel3.Dock = System.Windows.Forms.DockStyle.Left; this.panel3.Location = new System.Drawing.Point(0, 0); this.panel3.Name = panel3; this.panel3.Size = new System.Drawing.Size(297, 38); this.panel3.TabIndex = 0; / / panel5 / this.panel5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel5.Controls
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1