Can anyone help me with a problem with the IsPlaying boolean on a Pi

I am struggling to get a MP3 player working on the Raspberry Pi. My problem is that I cannot seem to get the sound.IsPlaying Boolean to help me identify when a MP3 file has stopped playing. It constantly is set to True, even after the file has finished playing.

My code behaves better and works perfectly when running in the IDE under Windows, but it fails as described above when I try and run it a Pi with Rasbian Jessie. I should add that the sound plays just fine on the Pi - its just that I am unable to detect when it has finished. I’ve also tried using a USB sound card on the Pi (instead of its built-in PCM module), but that hasn’t helped.

Thinking that it might be something else in my code that I might have mucked up, I went back to the simple Sound Player example included with Xojo, and added a msound.IsPlaying test in a 100msec timer event, just to check. Again, it works perfectly in the IDE but fails on the Raspberry Pi too.

I am very new to Linux (and XoJo), so if anyone can offer me some guidance and/or workaround it really would be most appreciated.

I am using a Raspberry Pi 2 and Raspbian Jessie with all the latest updates installed.

Thanks,
Ralph

You don’t post any code so i will try this way.
If understand right you don’t know if the mp3 playing or not?
Create a global property “mysound as sound” and one Property "mp3status as boolean "then

[code]Dim f as FolderItem = GetFolderItem(“MySong.mp3”)
If f <> nil then
MySound= f.OpenAsSound

If MySound.IsPlaying then
Mp3status =true
Else
  Mp3status =false
End if

Else
//user cancelled
End if[/code]

Thanks for your reply Loannis.

Yes, I essentially need to poll and check if the mp3 is still playing. Or more accurately, I actually need to know when it finishes playing, so I can go off and do some other things.

Essentially, the way you have described in your code example is how I am trying to do it, with one slight difference

  • the OpenAsSound command which opens the MP3 is in a “button” code block, actioned when the user clicks the “Play” button
  • the MySound.IsPlaying check is inside a timer event which fires every 0.1seconds, so that within a short time after the file has finished, the program knows about it and can go andexecute some other functions.

As I say, it works fine in the Xojo IDE. But on the Raspberry Pi, the IsPlaying flag goes True when the MP3 starts playing, but never goes back to False after the music file has finished playing. I have it confirmed this behaviour with several MP3 files, so I don’t think it is the format of the file.

I should have also said, it is a desktop application on the Raspberry Pi.

Kind regards,
Ralph

Ralph you don’t post any code so i don’t know how is your code in your project.
Do you use a local variable?Like “Dim MySound as sound” ?
If yes maybe is go out of scope if you change windows,etc?
You say “but never goes back to False after the music file has finished playing” That mean you variable cannot be checked if is true or false!!
Try with the two properties and make them global inside a module and test it?
Create a textfield and check the result true/false there,when you press the play,stop buttons.

Thanks again Loannis for the reply.

Here is the code I am using (I have simplified the code segments to reduce it to the simplest program that demonstrates the problem I am having)…

Firstly, I have a global variable property called playbackSound, with type Sound and scope Global.

Then in the main window (there is only one window in this project, I have a button called Play (scope Public) with the following code in the Action event handler:

  Dim downloadFile As FolderItem = SpecialFolder.CurrentWorkingDirectory.Child("myPlayFile.mp3")
  If downloadFile <> Nil and downloadFile.Exists Then
    playbackSound = downloadFile.OpenAsSound
    playbackSound.Play
    Timer1.mode=2
  End If 

Then I have a timer control called Timer1 with a period set to 100msec and Public scope. In its Action event handler, I have:

  if playbackSound <> nil and playbackSound.isplaying=false then
    Timer1.mode=0
    msgbox("Audio playback has finished normally.")
  end if

In Windows, it works fine and the MsgBox displays when when the mp3 finishes playing. On the Raspberry Pi however, after the playback has concluded, the MsgBox is never shown.

Any further assistance would be warmly appreciated.

Thanks again,
Ralph.

This sounds like a bug. It could be a general Linux bug or it could be Pi-specific. Please create a Feedback case with a sample project so we can look into it.

Hi Paul,

Thanks for your message. I suspect that you are correct, so I will create a simple project that demonstrates the anomaly, and log via the feedback mechanism as you have suggested.

For anyone else reading this thread who might be struggling with the same issue, I have discovered a workaround. Instead of using the Sound class, I can instead Shell to the “omxplayer” that is provided in the Raspbian Jessie distribution. This technique only seems to work in Synchronous mode (mode 0) so code execution is blocked until the mp3 has finished playing - but in my application, I can live with this limitation.

Warm regards,
Ralph Parkhurst

Just to correct (and add) to my last post, I have found the omxplayer to provide a very effective workaround to the sound.IsPlaying issue.

And, after learning how the Shell modes work, I can confirm that omxplayer does indeed work well in interactive (shell mode 2), thus without any code blocking. By checking when the Shell.Completed event fires, I can now easily determine when the mp3 has finished playing.

Warm regards,
Ralph.

Hi @Ralph Parkhurst -

I’m affected by this bug as well. Did you file a bug report on this? I found one bug when searching for “IsPlaying” (35266) but didn’t find yours - which I would like to vote on too.

Since I had the demo project ready to go I went ahead and submitted the bug report here: <https://xojo.com/issue/45484>

My (https://xojo.com/issue/45484)>]bug report (#45484) on this has been verified by Xojo today.

If this bug is an issue for you please add the feedback to “My Top Cases” in the Feedback app to help raise the rank of the issue.

Notes: (also in the feedback bug/case):

If you manually stop the sound file from playing it works. That’s the not the issue here.

The issue is that when the sound file is finished playing the .IsPlaying boolean property never changes back to false for ARM32 Linux on Raspian 8.

This means that my music playing application will have no idea when the sound file has finished playing, and will then never start the next song to play.