Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Update GUI from AudioManager  (Read 2789 times)

0 Members and 1 Guest are viewing this topic.

s.baus

  • Newbie
  • *
  • Posts: 45
    • View Profile
Update GUI from AudioManager
« on: July 16, 2014, 11:42:08 am »
Hello everybody,

I want to use SFML in my little application, and have done some bindings. The application is written in C#, uses Mono on Linux and .NET on Windows. Now I want to update the GUI (Mainwindow) so it can display the current position. Therefore I wanted to add a thread in my audiomanager, that periodically triggers the GUI to grab new values (1 time a second), but that fails, since the thread of SFML seems to get out of control. Have you ever done something like this? How do others implement audio players? Any examples are welcome.
I hope you understand what I want to achieve, otherwise ask ;).
Greetings
Sven
AudioCuesheetEditor, your #1 CuesheetEditor.

http://sourceforge.net/projects/audiocuesheet

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Update GUI from AudioManager
« Reply #1 on: July 16, 2014, 11:54:53 am »
Define "the thread of SFML seems to get out of control". ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

s.baus

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Update GUI from AudioManager
« Reply #2 on: July 16, 2014, 12:40:34 pm »
Well it seems like it  just doesn't react to pause() or stop(), but if I ask for play() another thread starts and plays also the music, so that 2 musics are played.
AudioCuesheetEditor, your #1 CuesheetEditor.

http://sourceforge.net/projects/audiocuesheet

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Update GUI from AudioManager
« Reply #3 on: July 16, 2014, 12:57:00 pm »
Please provide a complete and minimal example that reproduces the problem.
Laurent Gomila - SFML developer

s.baus

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Update GUI from AudioManager
« Reply #4 on: July 16, 2014, 08:32:57 pm »
Ok, I hope this code helps a bit to understand what I'm trying to achieve:

namespace AudioCuesheetEditor.AudioBackend
{
    public class AudioManagerSFML : AudioManager
    {
[...]
private bool checkAndPlayMusic(TimeSpan offset)
        {
            log.debug("checkAndPlayMusic called with " + offset);
            bool playing = false;
            //Always set the music, because the user might have changed it
            this.setMusic();
            if (this.music != null)
            {
                this.music.PlayingOffset = offset;
                this.music.Play();
                Timer tUpdateGUI = new Timer(1000);
                tUpdateGUI.Elapsed += delegate(object sender, ElapsedEventArgs e)
                {
                    log.debug("updateGUI");
                    Gtk.Application.Invoke(delegate {
                        this.objProgram.getObjMainWindow().updateAudiodataOnGUI();
                    });
                    if ((this.getPlayState() == PlayState.Paused) || (this.getPlayState() == PlayState.Stopped))
                    {
                        this.stop();
                    }
                };
                tUpdateGUI.AutoReset = true;
                tUpdateGUI.Start();
                playing = true;
            }
            return playing;
        }
[...]
    }
}

public partial class MainWindow : Gtk.Window
{
[...]
public void updateAudiodataOnGUI()
    {
        this.entAudiofilePosition.Text = this.objProgram.getAudioManager().getPosition().ToString();
    }
[...]
}

First enter of checkAndPlayMusic works fine, the music starts, the function gets called, and the log messages come. If I want to use this.music.pause(), it doesn't react, the breakpoint is never reached. Any ideas, why?
AudioCuesheetEditor, your #1 CuesheetEditor.

http://sourceforge.net/projects/audiocuesheet

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Update GUI from AudioManager
« Reply #5 on: July 16, 2014, 09:02:38 pm »
Please read this and post a code which is truly complete and minimal. Not incomplete pieces of your original project.
Laurent Gomila - SFML developer

 

anything