Getting A Sound File To Stop Playing

I am using Splash Screen music in my app when it starts up, but I want the music to stop when the user pushes a button.

I can get the music to play ok, but I can’t make it stop once it starts.

I attached an example project below.

link Example Project

The Play Button has this code:

//Play Music If TargetWin32 Then MoviePlayer1.PlayerType=2 SplashW2.Play Else Splash2.Play End If

The Stop Code is:

[code]    //Stops  Music
    MoviePlayer1.Stop[/code]

The two sound files are just dragged into the project. I have an MP3 for macOS and a WAV file for Windows.

Does anyone know how I can make the music stop on demand?

Never mind. I just figured it out.

@James Redway would you mind adding the solution and marking it as your answer. Would help people with the same issue in the future.

Sure

I am using Splash Screen music in my app when it starts up, but I want the music to stop when the user pushes a button.

I was able to get the music to play ok, but I couldn’t make it stop once it starts.

Play Code:

    //Play Music
[code]      If TargetWin32 Then
            MoviePlayer1.PlayerType=2
            SplashW2.Play
    Else
        Splash2.Play
     End If[/code]

The Stop Code is:

    //Stops  Music
  [code]  MoviePlayer1.Stop[/code]

The two sound files are just dragged into the project. I have an MP3 for macOS and a WAV file for Windows.

I realized as soon as I posted my message that the MoviePlayer had nothing to do with the playing of the music and was not even necessary. So I changed the code to this, and it worked fine.

//Play Music

If TargetWin32 Then SplashW2.Play Else Splash2.Play End If

//StopMusic

      [code]If TargetWin32 Then
         SplashW2.Stop
    Else
        Splash2.Stop
     End If[/code]

Macs will play .wav just fine. Not really a reason to have 2 separate sound files thus bloating your app.

Thanks Roger. I will get rid of the MP3 file.

If you like to play MP3 on Windows, you can use our WindowsPlayerMBS class.