0

When I launch my application, background music starts. The code below allows me to get that, provided that I integrate a WAV audio file into the resources.

Unfortunately, a WAV audio file is very heavy: my file is 40 MB. If I used the same audio file in mp3, it would be: 2.75 MB.

Visual Basic does not accept mp3 files. Is there not a way around this problem? Thank you for your reply.

Class MainWindow

'Music Background.

Private Sub Main_Form_Loaded(sender As Object, e As RoutedEventArgs) Handles Main_Form.Loaded
    Dim son = New Media.SoundPlayer(My.Resources.My_Music)
    son.PlayLooping()
Eratos
  • 37
  • 1
  • 7
  • Possible duplicate of [Playing a MP3 file in a WinForm application](https://stackoverflow.com/questions/15025626/playing-a-mp3-file-in-a-winform-application) – GSerg May 27 '19 at 18:57
  • GSerg, thank you for the link. – Eratos May 27 '19 at 19:23

1 Answers1

1

Thank you GSerg, your link has allowed me to find the solution: the code below works perfectly. Previously, install Naudio under Visual Studio. Then, Imports System.IO - Imports NAudio.Wave

Music Background.

Private Sub Form_Main_Loaded(sender As Object, e As RoutedEventArgs) Handles Form_Main.Loaded
    Dim mp3file As MemoryStream = New MemoryStream(My.Resources.My.Music)        
    Dim mp3Reader As Mp3FileReader = New Mp3FileReader(mp3file)
    Dim waveOut As WaveOut = New WaveOut
    waveOut.Init(mp3Reader)
    waveOut.Play()

Another question: is there a function or an additional code to play music loop? Thank you for your reply.

Eratos
  • 37
  • 1
  • 7