SFML community forums

Bindings - other languages => DotNet => Topic started by: s.baus on July 16, 2014, 11:42:08 am

Title: Update GUI from AudioManager
Post by: s.baus 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
Title: Re: Update GUI from AudioManager
Post by: eXpl0it3r on July 16, 2014, 11:54:53 am
Define "the thread of SFML seems to get out of control". ;)
Title: Re: Update GUI from AudioManager
Post by: s.baus 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.
Title: Re: Update GUI from AudioManager
Post by: Laurent on July 16, 2014, 12:57:00 pm
Please provide a complete and minimal example that reproduces the problem.
Title: Re: Update GUI from AudioManager
Post by: s.baus 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?
Title: Re: Update GUI from AudioManager
Post by: Laurent on July 16, 2014, 09:02:38 pm
Please read this (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368) and post a code which is truly complete and minimal. Not incomplete pieces of your original project.