none
想製作PPC音樂播放程式有無相關元件? RRS feed

  • 問題

  • 如題,當然不可能只有播放音樂那麼簡單...

    可是沒有播放音樂等於不能完成其他功能...!

     

    希望能做出可以播放MP3、WMA的撥放器

    兩種音樂格式就夠了!!....

     

    請大家幫忙嚕> _ <!!!

    2007年7月18日 下午 10:26

解答

  • Fmod元件即可達到撥放MP3功能元件請至原網站下載 http://www.fmod.org

    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Text

    Public Class cFmod
        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Init", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Init(ByVal mixrate As Integer, ByVal maxsoftwarechannels As Integer, ByVal flags As Integer) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_GetLength", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_GetLength(ByVal fstream As IntPtr) As Integer
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_GetPosition", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_GetPosition(ByVal fstream As IntPtr) As UInt32
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Open", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Open(ByVal data As IntPtr, ByVal mode As Integer, ByVal offset As Integer, ByVal length As Integer) As IntPtr
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Play", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Play(ByVal channel As Integer, ByVal fstream As IntPtr) As Integer
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_SetPosition", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_SetPosition(ByVal fstream As IntPtr, ByVal position As UInt32) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Stop", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Stop(ByVal fstream As IntPtr) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Close", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Sub fmod_Close()
        End Sub

        Private Shared strSoundTrack As String = String.Empty
        Private Shared booOnPause As Boolean = False
        Private Shared currentPosition As Integer = 0
        Private Shared soundHandle As IntPtr = IntPtr.Zero
        Private Shared currentSoundLength As Integer = 0
        Private Shared uPausePosition As UInt32

        Private Shared WithEvents timSound As New Timer
        Private Shared WithEvents timEnd As New Timer

        Public Shared Function test_play() As Boolean
            On Error Resume Next

            fmod_Init(44100, 16, 0)

            If Err.Number = 0 Then
                test_play = True
            End If

        End Function


        Private Shared Sub timSound_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timSound.Tick
            uPausePosition = fmod_GetPosition(soundHandle)
            currentPosition = CInt(uPausePosition.ToString)


            If currentPosition >= currentSoundLength Then
                timSound.Enabled = False

                timEnd.Interval = 5000
                timEnd.Enabled = True

            End If

        End Sub


        Private Shared Sub timEnd_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timEnd.Tick

            stop_track()
            timEnd.Enabled = False
        End Sub


        Public Shared Function play_track(ByVal path As String)


            fmod_Init(44100, 16, 0)

            Dim soundStream As IntPtr = fmod_getStream(path)

            soundHandle = fmod_Open(soundStream, &H10 Or &H20 Or &H100, 0, 0)
            currentSoundLength = fmod_GetLength(soundHandle)

            If booOnPause Then
                fmod_SetPosition(soundHandle, uPausePosition)
                fmod_Play(1, soundHandle)
                booOnPause = False
            Else
                fmod_Play(0, soundHandle)
            End If


            timSound.Enabled = True

            'fmod_Close()
            'soundStream = Nothing
            'currentSoundLength = Nothing

        End Function


        Public Shared Function stop_track()
            If soundHandle.ToInt32 > 0 Then


                uPausePosition = fmod_GetPosition(soundHandle)
                fmod_Stop(soundHandle)

                fmod_Close()

            End If
        End Function

        Public Shared Function fmod_getStream(ByVal filename As String) As IntPtr
            Dim filenames As Byte() = Encoding.Default.GetBytes(filename & vbNullChar)
            Dim hfile As GCHandle = GCHandle.Alloc(filenames, GCHandleType.Pinned)

            If Environment.Version.Major = 1 Then
                fmod_getStream = New IntPtr(hfile.AddrOfPinnedObject().ToInt32 + 4)
            Else
                fmod_getStream = hfile.AddrOfPinnedObject()
            End If

            If hfile.IsAllocated Then
                hfile.Free()
            End If
        End Function

        Public Shared Function fmod_getStream_New(ByVal filename As String) As IntPtr
            Dim filenames As Byte() = Encoding.Default.GetBytes(filename & vbNullChar)
            Dim p As IntPtr = LocalAlloc(Convert.ToUInt32(LMEM_FIXED Or LMEM_ZEROINIT), Convert.ToUInt32(filenames.Length))
            If Not p.Equals(IntPtr.Zero) Then
                Marshal.Copy(filenames, 0, p, filenames.Length)
            End If
            fmod_getStream_New = p
        End Function

        '===========================================================================================================================

        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalAlloc(ByVal uFlags As UInt32, ByVal uBytes As UInt32) As IntPtr
        End Function

        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr
        End Function
        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal uBytes As UInt32, ByVal fuFlags As UInt32) As IntPtr
        End Function

        Public Const LMEM_FIXED As Integer = 0
        Public Const LMEM_MOVEABLE As Integer = 2
        Public Const LMEM_ZEROINIT As Integer = &H40

     

    威嘉實業kylin

    2007年7月19日 上午 04:42
  • 如果打算用fmod這個library的話,你要去該網站上download的那個網頁,選擇
    FMOD 3.75 Programmers API
    Windows CE那一項,
    因為只有
    FMOD 3有支援PPC
    FMOD EX不支援
    2007年7月21日 下午 05:45

所有回覆

  • Fmod元件即可達到撥放MP3功能元件請至原網站下載 http://www.fmod.org

    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Text

    Public Class cFmod
        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Init", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Init(ByVal mixrate As Integer, ByVal maxsoftwarechannels As Integer, ByVal flags As Integer) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_GetLength", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_GetLength(ByVal fstream As IntPtr) As Integer
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_GetPosition", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_GetPosition(ByVal fstream As IntPtr) As UInt32
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Open", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Open(ByVal data As IntPtr, ByVal mode As Integer, ByVal offset As Integer, ByVal length As Integer) As IntPtr
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Play", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Play(ByVal channel As Integer, ByVal fstream As IntPtr) As Integer
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_SetPosition", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_SetPosition(ByVal fstream As IntPtr, ByVal position As UInt32) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Stream_Stop", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Function fmod_Stop(ByVal fstream As IntPtr) As Boolean
        End Function

        <DllImport("fmodce.dll", EntryPoint:="FSOUND_Close", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Winapi)> _
        Public Shared Sub fmod_Close()
        End Sub

        Private Shared strSoundTrack As String = String.Empty
        Private Shared booOnPause As Boolean = False
        Private Shared currentPosition As Integer = 0
        Private Shared soundHandle As IntPtr = IntPtr.Zero
        Private Shared currentSoundLength As Integer = 0
        Private Shared uPausePosition As UInt32

        Private Shared WithEvents timSound As New Timer
        Private Shared WithEvents timEnd As New Timer

        Public Shared Function test_play() As Boolean
            On Error Resume Next

            fmod_Init(44100, 16, 0)

            If Err.Number = 0 Then
                test_play = True
            End If

        End Function


        Private Shared Sub timSound_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timSound.Tick
            uPausePosition = fmod_GetPosition(soundHandle)
            currentPosition = CInt(uPausePosition.ToString)


            If currentPosition >= currentSoundLength Then
                timSound.Enabled = False

                timEnd.Interval = 5000
                timEnd.Enabled = True

            End If

        End Sub


        Private Shared Sub timEnd_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timEnd.Tick

            stop_track()
            timEnd.Enabled = False
        End Sub


        Public Shared Function play_track(ByVal path As String)


            fmod_Init(44100, 16, 0)

            Dim soundStream As IntPtr = fmod_getStream(path)

            soundHandle = fmod_Open(soundStream, &H10 Or &H20 Or &H100, 0, 0)
            currentSoundLength = fmod_GetLength(soundHandle)

            If booOnPause Then
                fmod_SetPosition(soundHandle, uPausePosition)
                fmod_Play(1, soundHandle)
                booOnPause = False
            Else
                fmod_Play(0, soundHandle)
            End If


            timSound.Enabled = True

            'fmod_Close()
            'soundStream = Nothing
            'currentSoundLength = Nothing

        End Function


        Public Shared Function stop_track()
            If soundHandle.ToInt32 > 0 Then


                uPausePosition = fmod_GetPosition(soundHandle)
                fmod_Stop(soundHandle)

                fmod_Close()

            End If
        End Function

        Public Shared Function fmod_getStream(ByVal filename As String) As IntPtr
            Dim filenames As Byte() = Encoding.Default.GetBytes(filename & vbNullChar)
            Dim hfile As GCHandle = GCHandle.Alloc(filenames, GCHandleType.Pinned)

            If Environment.Version.Major = 1 Then
                fmod_getStream = New IntPtr(hfile.AddrOfPinnedObject().ToInt32 + 4)
            Else
                fmod_getStream = hfile.AddrOfPinnedObject()
            End If

            If hfile.IsAllocated Then
                hfile.Free()
            End If
        End Function

        Public Shared Function fmod_getStream_New(ByVal filename As String) As IntPtr
            Dim filenames As Byte() = Encoding.Default.GetBytes(filename & vbNullChar)
            Dim p As IntPtr = LocalAlloc(Convert.ToUInt32(LMEM_FIXED Or LMEM_ZEROINIT), Convert.ToUInt32(filenames.Length))
            If Not p.Equals(IntPtr.Zero) Then
                Marshal.Copy(filenames, 0, p, filenames.Length)
            End If
            fmod_getStream_New = p
        End Function

        '===========================================================================================================================

        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalAlloc(ByVal uFlags As UInt32, ByVal uBytes As UInt32) As IntPtr
        End Function

        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr
        End Function
        <DllImport("coredll.dll", SetLastError:=True)> _
        Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal uBytes As UInt32, ByVal fuFlags As UInt32) As IntPtr
        End Function

        Public Const LMEM_FIXED As Integer = 0
        Public Const LMEM_MOVEABLE As Integer = 2
        Public Const LMEM_ZEROINIT As Integer = &H40

     

    威嘉實業kylin

    2007年7月19日 上午 04:42
  • 因為剛接觸VB.NET...

    可以講一下要怎麼使用嗎?

    下載下來的Fmod是.DMG檔嗎?

    是的話要怎樣使用?

    2007年7月19日 上午 08:07
  • 如果打算用fmod這個library的話,你要去該網站上download的那個網頁,選擇
    FMOD 3.75 Programmers API
    Windows CE那一項,
    因為只有
    FMOD 3有支援PPC
    FMOD EX不支援
    2007年7月21日 下午 05:45