Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Need Help with audio using the Win32 API

Hey all,

I've been trying to change the audio in RPGXP over to my own module, but I'm having trouble getting my calls to the Win32API to work.  So far I'm just trying to get it to play a single .mp3 file using in RMXP, but my code does not play the file - but it doesn't throw any errors either.  Here is the code:

Code:
  def Audio.bgm_play( fileName, volume, pitch )
    mciSendString = Win32API.new("winmm", "mciSendString", ['P','P','L','L'], 'L')
    
    mciSendString.call('open C:\Documents and Settings\FROST\Desktop\Game\Audio\BGM\Game_Theme.mp3 type waveaudio alias voice1', nil, 0, 0)
    
    mciSendString.call('play voice1', nil, 0, 0)
  end

I've also tried doing the same thing just in Ruby alone, but it produced the same result - no music, and no errors.  Here's the code for that:

Code:
require 'Win32API'

mciSendString = Win32API.new("winmm", "mciSendString", ['P','P','L','L'], 'L')

mciSendString.call('open C:\Documents and Settings\FROST\Desktop\Game\Audio\BGM\Game_Theme.mp3 type waveaudio alias voice1', nil, 0, 0)

mciSendString.call('play voice1', nil, 0, 0)

loop do
  #...
end

Does anyone know why this code does not work?  I'm sure it's something simple that I'm not seeing.

I'd appreciate any help, thanks!
 
I replaced only waveoudio with MPEGVideo (the right type for MP3s but myabe it won't work with all bitrates):

Code:
 mciSendString.call('open C:\Documents and Settings\FROST\Desktop\Game\Audio\BGM\Game_Theme.mp3 type MPEGVideo alias voice1', nil, 0, 0)

Btw you don't have to write the direct path: 'open Audio\BGM\Game_Theme.mp3 type MPEGVideo alias voice1'
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top