Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > Visual C# ทำให้เล่นไฟล์ Play MP3 อย่างไรครับ (.NET, C#)


 

[.NET] Visual C# ทำให้เล่นไฟล์ Play MP3 อย่างไรครับ (.NET, C#)

 
Topic : 066137

Guest



Visual c# ทำให้เล่นไฟล์ mp3 อย่างไรครับ ?????
ขอบคุณล่วงหน้านะครับ :)



Tag : .NET, C#

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-09-07 18:46:33 By : ต้อง View : 1862 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (C#)
01.private void Filler(IntPtr data, int size)
02.{
03.    byte[] b = new byte[size];
04.    if (m_AudioStream != null)
05.    {
06.        int pos = 0;
07.        while (pos < size)
08.        {
09.            int toget = size - pos;
10.            int got = m_AudioStream.Read(b, pos, toget);
11.            if (got < toget)
12.                m_AudioStream.Position = 0; // loop if the file ends
13. 
14.            pos += got;
15.        }
16.    }
17.    else
18.    {
19.        for (int i = 0; i < b.Length; i++)
20.            b[i] = 0;
21.    }
22.    System.Runtime.InteropServices.Marshal.Copy(b, 0, data, size);
23.}


http://www.codeproject.com/KB/audio-video/cswavplay.aspx
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-09 22:10:27 By : webmaster
 

 

No. 2



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (C#)
001.using System;
002.using System.Collections.Generic;
003.using System.Linq;
004.using System.Text;
005.using System.Runtime.InteropServices;
006.using System.IO;
007. 
008.namespace DDSoundEngine
009.{
010.    class SimplePlaySound : IDisposable
011.    {
012.        byte[] Sbuffer;
013. 
014.        string path;
015. 
016.        bool _buffer;
017. 
018.        public SimplePlaySound(string fileName, bool buffer)
019.        {
020.            if (!System.IO.File.Exists(fileName))
021.            {
022.                throw new NotImplementedException("Error: File Name Incorrect");
023.            }
024. 
025.            _buffer = buffer;
026. 
027.            if (buffer)
028.            {
029.                using (FileStream s = new FileStream(fileName, FileMode.Open))
030.                {
031.                    Sbuffer = new byte[s.Length];
032.                    s.Read(Sbuffer, 0, (int)s.Length);
033.                }
034.            }
035.            else
036.            {
037.                path = fileName;
038.            }
039.        }
040.        // PlaySound()
041.        [DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
042.        static extern bool PlaySound(string pszSound,
043.            IntPtr hMod, SoundFlags sf);
044. 
045.        [DllImport("winmm.dll", SetLastError = true)]
046.        static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags fdwSound);
047. 
048.        [DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
049.        static extern bool sndPlaySound(IntPtr ptr, int fuSound);
050. 
051. 
052.        [Flags]
053.        public enum SoundFlags : int
054.        {
055.            SND_SYNC = 0x0000,  /* play synchronously (default) */
056.            SND_ASYNC = 0x0001,  /* play asynchronously */
057.            SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
058.            SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
059.            SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
060.            SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
061.            SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
062.            SND_ALIAS = 0x00010000, /* name is a registry alias */
063.            SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
064.            SND_FILENAME = 0x00020000, /* name is file name */
065.            SND_RESOURCE = 0x00040004,  /* name is resource name or atom */
066.            SND_PURGE = 0x0040 /* used in stopiing sounds*/
067.        }
068. 
069.        public void Play()
070.        {
071.            if (_buffer)
072.            {
073.                PlaySound(Sbuffer, IntPtr.Zero, SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC);
074.            }
075.            else
076.            {
077.                PlaySound(path, new System.IntPtr(), SoundFlags.SND_SYNC);
078.            }
079.        }
080. 
081.        public void PlayLoop()
082.        {
083.            if (_buffer)
084.            {
085.                PlaySound(Sbuffer, IntPtr.Zero, SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC | SoundFlags.SND_LOOP);
086.            }
087.            else
088.            {
089.                PlaySound(path, new System.IntPtr(), SoundFlags.SND_SYNC | SoundFlags.SND_LOOP);
090.            }
091.        }
092. 
093.        public void Stop()
094.        {
095.            if (_buffer)
096.            {
097.                PlaySound((string)null, IntPtr.Zero , 0);
098.            }
099.            else
100.            {
101.                PlaySound((string)null , IntPtr.Zero , 0);
102.            }
103.        }
104.         
105.        #region Dispose
106.        // Implement IDisposable.
107.        // Do not make this method virtual.
108.        // A derived class should not be able to override this method.
109.        public void Dispose()
110.        {
111.            Dispose(true);
112.            // This object will be cleaned up by the Dispose method.
113.            // Therefore, you should call GC.SupressFinalize to
114.            // take this object off the finalization queue
115.            // and prevent finalization code for this object
116.            // from executing a second time.
117.            GC.SuppressFinalize(this);
118.        }
119. 
120. 
121.         
122.        // Track whether Dispose has been called.
123.        private bool disposed = false;
124. 
125.        // Dispose(bool disposing) executes in two distinct scenarios.
126.        // If disposing equals true, the method has been called directly
127.        // or indirectly by a user's code. Managed and unmanaged resources
128.        // can be disposed.
129.        // If disposing equals false, the method has been called by the
130.        // runtime from inside the finalizer and you should not reference
131.        // other objects. Only unmanaged resources can be disposed.
132.        private void Dispose(bool disposing)
133.        {
134.            // Check to see if Dispose has already been called.
135.            if (!this.disposed)
136.            {
137.                // If disposing equals true, dispose all managed
138.                // and unmanaged resources.
139.                if (disposing)
140.                {
141.                    //keep the app from crashing windows API by telling it to stop using any sound resources
142.                    PlaySound((string)null, IntPtr.Zero, 0);
143. 
144. 
145.                }
146. 
147.                disposed = true;
148. 
149.            }
150.        }
151.        #endregion
152. 
153. 
154.    }
155.}


http://www.daniweb.com/software-development/csharp/code/253704
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-09 22:11:48 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Visual C# ทำให้เล่นไฟล์ Play MP3 อย่างไรครับ (.NET, C#)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่