Results 1 to 4 of 4

Thread: playing mp3's through api

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    110

    playing mp3's through api

    the mci and media player controls are too slow, hitting the play button swaps the image with another, but its getting slowed down while the control plays the file. I'm thinking that using the api will be faster and allow the swap to occur instantaneously (or pretty close)

    anybody know of any documentation on using the api to play mp3 files (or wav, mid, etc, a player would be pretty useless if it only played one file type) or have any tips? much appreciated.

  2. #2
    Junior Member
    Join Date
    Mar 2002
    Location
    Porsgrunn,NORWAY
    Posts
    30

    Play wav using DX

    This is pasted from one of my games. hope it helps. it plays wav files in buffers. I stick to this method, i think its great.

    Public DirectX7Obj As New DirectX7
    Public DirectSoundObj As DirectSound
    Public Level1Music As DirectSoundBuffer
    Public Level2Music As DirectSoundBuffer
    Public StartupMusic As DirectSoundBuffer

    Public WallHit As DirectSoundBuffer
    Public DamageBrick As DirectSoundBuffer
    Public BrickDestroy As DirectSoundBuffer
    Public HardBrickDestroy As DirectSoundBuffer
    Public MetalHit As DirectSoundBuffer
    Public Clap As DirectSoundBuffer
    Public PaddleHit As DirectSoundBuffer
    Public EjectBall As DirectSoundBuffer
    Public GameOverLaugh As DirectSoundBuffer
    Sub InitSound()
    InitDirectSound
    ChDir CheckPath(App.Path)
    Set Level1Music = CreateSound("SOUND\Level1Music.wav")
    Set Level2Music = CreateSound("SOUND\Level2Music.wav")
    Set StartupMusic = CreateSound("SOUND\StartupMusic.wav")

    Set MetalHit = CreateSound("SOUND\MetalHit.wav")
    Set BrickDestroy = CreateSound("SOUND\BrickDestroy.wav")
    Set HardBrickDestroy = CreateSound("SOUND\HardBrickDestroy.wav")
    Set DamageBrick = CreateSound("SOUND\DamageBrick.wav")
    Set WallHit = CreateSound("SOUND\WallHit.wav")
    Set Clap = CreateSound("SOUND\Clap.wav")
    Set PaddleHit = CreateSound("SOUND\PaddleHit.wav")
    Set EjectBall = CreateSound("SOUND\EjectBall.wav")

    Set GameOverLaugh = CreateSound("SOUND\GameOverLaugh.wav")

    End Sub

    Sub InitDirectSound()
    Set DirectSoundObj = DirectX7Obj.DirectSoundCreate("")
    DirectSoundObj.SetCooperativeLevel Startup.hwnd, DSSCL_PRIORITY
    End Sub

    Function CreateSound(FileName As String) As DirectSoundBuffer
    Dim BufferDesc As DSBUFFERDESC
    Dim WaveFormat As WAVEFORMATEX
    BufferDesc.lFlags = DSBCAPS_STATIC
    Set CreateSound = _
    DirectSoundObj.CreateSoundBufferFromFile(FileName, BufferDesc, WaveFormat)
    End Function

    Public Sub PlaySound(sound As DirectSoundBuffer, CloseFirst As Boolean, LoopSound As Boolean)

    If CloseFirst Then
    sound.Stop
    sound.SetCurrentPosition 0
    End If
    If LoopSound Then
    sound.Play 1
    Else
    sound.Play 0
    End If
    End Sub

  3. #3
    Junior Member
    Join Date
    Mar 2002
    Location
    Porsgrunn,NORWAY
    Posts
    30
    remember to activate direct x in references inside vb :=)

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I'm currently working on an Mp3 decompressor (Mp3 -> Wav) so if I ever finish I'll let you know.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width