planetis-m / naylib

Yet another raylib Nim wrapper
MIT License
181 stars 10 forks source link

Music and Web Builds #98

Open HVukman opened 5 months ago

HVukman commented 5 months ago

I tried to recreate the music example from the website, but the music is not playing. There is no error or a crash. System: WSL with Ubuntu

proc main =
  # Initialization
  # --------------------------------------------------------------------------------------
  initWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)")
  defer: closeWindow() # Close window and OpenGL context

  initAudioDevice() # Initialize audio device
  defer: closeAudioDevice() # Close audio device (music streaming is automatically stopped)

  let music = loadMusicStream("resources/country.mp3")

  # 1 second delay (device sampleRate*channels)

  var pause = false # Music playing paused
  when defined(emscripten):
    emscriptenSetMainLoop(updateDrawFrame, 0, 1)
  else:
    setTargetFPS(60) # Set our game to run at 60 frames-per-second
  # --------------------------------------------------------------------------------------
  # Main game loop
  while not windowShouldClose(): # Detect window close button or ESC key
    # Update
    # ------------------------------------------------------------------------------------
    updateMusicStream(music) # Update music buffer with new stream data

    # Restart music playing (stop and play)
    if isKeyPressed(Space):
        stopMusicStream(music)
        playMusicStream(music)

    # Pause/Resume music playing
    if isKeyPressed(P):
      pause = not pause
      if pause: pauseMusicStream(music)
      else: resumeMusicStream(music)

    # Get normalized time played for current music stream
    timePlayed = getMusicTimePlayed(music)/getMusicTimeLength(music)
    if timePlayed > 1: timePlayed = 1 # Make sure time played is no longer than music
    # ------------------------------------------------------------------------------------
    # Draw
    # ------------------------------------------------------------------------------------
    updateDrawFrame()
    # ------------------------------------------------------------------------------------

main()

music_example.zip

planetis-m commented 5 months ago

I have limited time to work on naylib, so please verify that your problem is caused by naylib and not something else. You can ask for help in discord first and then report the issue here. I can see that you forgot to include the minshell.html and the resources folder in your zipped file.

planetis-m commented 5 months ago

image