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,027

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



 

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 : 1789 Reply : 2
 

 

No. 1



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

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

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

Code (C#)
private void Filler(IntPtr data, int size)
{
    byte[] b = new byte[size];
    if (m_AudioStream != null)
    {
        int pos = 0;
        while (pos < size)
        {
            int toget = size - pos;
            int got = m_AudioStream.Read(b, pos, toget);
            if (got < toget)
                m_AudioStream.Position = 0; // loop if the file ends

            pos += got;
        }
    }
    else
    {
        for (int i = 0; i < b.Length; i++)
            b[i] = 0;
    }
    System.Runtime.InteropServices.Marshal.Copy(b, 0, data, size);
}


http://www.codeproject.com/KB/audio-video/cswavplay.aspx






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-09-09 22:10:27 By : webmaster
 


 

No. 2



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

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

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

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace DDSoundEngine
{
    class SimplePlaySound : IDisposable
    {
        byte[] Sbuffer;

        string path;

        bool _buffer;

        public SimplePlaySound(string fileName, bool buffer)
        {
            if (!System.IO.File.Exists(fileName))
            {
                throw new NotImplementedException("Error: File Name Incorrect");
            }

            _buffer = buffer;

            if (buffer)
            {
                using (FileStream s = new FileStream(fileName, FileMode.Open))
                {
                    Sbuffer = new byte[s.Length];
                    s.Read(Sbuffer, 0, (int)s.Length);
                }
            }
            else
            {
                path = fileName;
            }
        }
        // PlaySound()
        [DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
        static extern bool PlaySound(string pszSound,
            IntPtr hMod, SoundFlags sf);

        [DllImport("winmm.dll", SetLastError = true)]
        static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags fdwSound);

        [DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
        static extern bool sndPlaySound(IntPtr ptr, int fuSound);


        [Flags]
        public enum SoundFlags : int
        {
            SND_SYNC = 0x0000,  /* play synchronously (default) */
            SND_ASYNC = 0x0001,  /* play asynchronously */
            SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
            SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
            SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
            SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
            SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
            SND_ALIAS = 0x00010000, /* name is a registry alias */
            SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
            SND_FILENAME = 0x00020000, /* name is file name */
            SND_RESOURCE = 0x00040004,  /* name is resource name or atom */
            SND_PURGE = 0x0040 /* used in stopiing sounds*/
        }

        public void Play()
        {
            if (_buffer)
            {
                PlaySound(Sbuffer, IntPtr.Zero, SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC);
            }
            else
            {
                PlaySound(path, new System.IntPtr(), SoundFlags.SND_SYNC);
            }
        }

        public void PlayLoop()
        {
            if (_buffer)
            {
                PlaySound(Sbuffer, IntPtr.Zero, SoundFlags.SND_MEMORY | SoundFlags.SND_ASYNC | SoundFlags.SND_LOOP);
            }
            else
            {
                PlaySound(path, new System.IntPtr(), SoundFlags.SND_SYNC | SoundFlags.SND_LOOP);
            }
        }

        public void Stop()
        {
            if (_buffer)
            {
                PlaySound((string)null, IntPtr.Zero , 0);
            }
            else
            {
                PlaySound((string)null , IntPtr.Zero , 0);
            }
        }
        
        #region Dispose
        // Implement IDisposable.
        // Do not make this method virtual.
        // A derived class should not be able to override this method.
        public void Dispose()
        {
            Dispose(true);
            // This object will be cleaned up by the Dispose method.
            // Therefore, you should call GC.SupressFinalize to
            // take this object off the finalization queue
            // and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }


        
        // Track whether Dispose has been called.
        private bool disposed = false;

        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    //keep the app from crashing windows API by telling it to stop using any sound resources
                    PlaySound((string)null, IntPtr.Zero, 0);


                }

                disposed = true;

            }
        }
        #endregion


    }
}


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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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