Viết chương trình play nhac

4 726 3
Viết chương trình play nhac

Đang tải... (xem toàn văn)

Thông tin tài liệu

Viết chương trình play nhac

Tôi đang học C# có viết một ứng dụng nghe nhạc xem phim nhỏ. Mới học được, Mong các bạn góp ý thảo luận, Chay rất tốt chỉ tốn mấy chục kb thôi, Nhưng có một điều khi mở các files nhạc có tên được gõ bằng unicode thì không chạy được.đây là code. sử dụng API Import winmm.dll. Nhưng khi chay thì không chơi được các bài hát với tên có kí tự unicode sao thế hè. Bà con có ai biết thì nói giùm nhé. đây là code của ứng dụng đó. Có gì thì cùng góp ý nhé.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 MultiPlay{public partial class Form1 : Form{private bool filedangmo = false;private bool lapkhong = false;private bool tamdung = false;public Form1(){InitializeComponent();}[DllImport("winmm.dll")]public static extern long mciSendString(string caulenh, StringBuilder strbuilder, int chieudai, IntPtr tinhieu);private StringBuilder sbf = new StringBuilder();public string trangthai(){mciSendString("status mediafile mode", sbf, sbf.Capacity, IntPtr.Zero);//MessageBox.Show(sbf.ToString());return sbf.ToString();}private void openToolStripMenuItem_Click(object sender, EventArgs e){if (trangthai() == "playing"){lenh = "close mediafile";this.pictureBox2.Visible = false;mciSendString(lenh, null, 0, IntPtr.Zero);openFileDialog1.Title = "Chọn Files nhạc (*.mpg,*.avi,*.dat)";openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*. mp3;*.mpg;*.dat;*.avi;*.wmv"; openFileDialog1.ShowDialog();filedangmo = true;}else{//if (trangthai() == "stopper")//{// lenh = "close mediafile";// mciSendString(lenh, null, 0, IntPtr.Zero);// openFileDialog1.Title = "Chọn Files nhạc (*.mpg,*.avi,*.dat)";// openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*. mp3;*.mpg;*.dat;*.avi;*.wmv";// openFileDialog1.ShowDialog();// filedangmo = true;//}lenh = "close mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);openFileDialog1.Title = "Chọn Files nhạc (*.mpg,*.avi,*.dat)";openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*. mp3;*.mpg;*.dat;*.avi;*.wmv";openFileDialog1.ShowDialog();filedangmo = true;}}string lenh;private void button1_Click(object sender, EventArgs e){lenh = "open \"" + this.openFileDialog1.FileName + "\" type mpegvideo alias mediafile style child parent "+this.pictureBox1.Handle.ToInt32();mciSendString(lenh, null, 0, IntPtr.Zero);lenh = "put mediafile window at 0 0 " + this.pictureBox1.Width + " " + this.pictureBox1.Height;if (filedangmo){this.Text = openFileDialog1.FileName;lenh = "play mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);this.pictureBox2.Visible = true;}else{MessageBox.Show("Chưa mở file"); }}private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e){hamfullscreen();}private void button2_Click(object sender, EventArgs e){lenh = "close mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);filedangmo = true;this.pictureBox2.Visible = false;}private void closeToolStripMenuItem_Click(object sender, EventArgs e){this.Close();filedangmo = false;}private void cửaSổRiêngToolStripMenuItem_Click(object sender, EventArgs e){hamcuaso();}private void button3_Click(object sender, EventArgs e){if(trangthai().Equals("stopper")){lenh = "play mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);}else{lenh = "stop mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);}}private void pictureBox1_Click(object sender, EventArgs e){hamfullscreen();}public void hamfullscreen(){lenh = "stop mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);lenh = "play mediafile fullscreen"; mciSendString(lenh, null, 0, IntPtr.Zero);}private void chạyToolStripMenuItem_Click(object sender, EventArgs e){hamcuaso();}private void hamcuaso(){lenh = "close mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);lenh = "open \"" + this.openFileDialog1.FileName + "\" type mpegvideo alias mediafile ";mciSendString(lenh, null, 0, IntPtr.Zero);lenh = "play mediafile";mciSendString(lenh, null, 0, IntPtr.Zero);}}}WEB hay giới thiệu mọi người: http://www.henho.com . Tôi đang học C# có viết một ứng dụng nghe nhạc xem phim nhỏ. Mới học được, Mong các bạn góp ý thảo. System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace MultiPlay{public partial class Form1 : Form{private bool filedangmo = false;private

Ngày đăng: 14/11/2012, 17:19

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan