Odd behavior of is_playing()

This forum is about all development around libVLC.
linus72982
New Cone
New Cone
Posts: 2
Joined: 16 Feb 2016 06:09

Odd behavior of is_playing()

Postby linus72982 » 16 Feb 2016 06:30

I am writing a music player and can't figure out why MediaPlayer.is_playing() seems to come back to me backward. Here is the relevant section:

Code: Select all

def handle_command_play(self, song=None, pointer=None): if song is not None and pointer is not None: self.song = self.set_song(song=song) self.playlist_pointer = pointer self.player.set_media(self.song) pause = 2 elif self.player.is_playing(): pause = 1 else: pause = 0 if pause < 2: self.player.set_pause(pause) # if pause is zero, resume -- if non-zero, pause else: self.player.play() return self.player.is_playing()
I did some printing to find out what was going on. I changed the last else to:

Code: Select all

else: print self.player.is_playing() self.player.play() print self.player.is_playing()
and it printed 0 0. When I return "not self.player.is_playing()", everything works wonderfully.

Any idea why this might be working backward for me? I'm looking at the source and it clearly says, "@return: 1 if the media player is playing, 0 otherwise \libvlc_return_bool."

EDIT: I should mention -- the media is playing and pausing just fine, the problem comes in that the return is what I use to change the play button image to the pause button image and that's working oddly. And, yes, I know the code doesn't have error-checking and is rough in some places -- this is an early draft proof-of-concept.

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Odd behavior of is_playing()

Postby Etoh » 24 Feb 2016 10:09

My guess is that it runs self.player.is_playing() before the state change between playing/pausing is finalised so uses the old state (because things are a little asynchronous due to threads).

I expect that if you want it to return the state it will be in after all changes have been executed then you need to use the functions own knowledge of how it has changed the state so that the same code that results in a change of state will also result in a change to what is returned.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 13 guests