Page 1 of 1

mpd_connection_new() only works onces

Posted: October 18th, 2018, 9:15 pm
by StefWe
I call the function and can then play or pause successfully. But after that I cannot execute a second command without calling mpd_connection_new() again.

Is that normal or i'm doing something wrong?

I would have expected the mpd_connection object to remain valid as long as my program is running or I call mpd_connection_free.

I appreciate any help.

Re: mpd_connection_new() only works onces

Posted: October 19th, 2018, 7:42 am
by max
Which function?

Re: mpd_connection_new() only works onces

Posted: October 19th, 2018, 8:30 am
by StefWe
i try to call the function mpd_connection_new() once at the start of my program.

Later in the program i used the object i get from mpd_connection_new() and run the mpd_send_play(). This is working.

But after that nothing else is working with this object. I need to call the function mpd_connection_new() again and than i can run for example the mpd_send_stop().

Hope I could explain it a little better.

Re: mpd_connection_new() only works onces

Posted: October 19th, 2018, 8:54 am
by max
mpd_send_play() does just what the name says: it sends the "play" command, but doesn't do anything else. Specifically, it doesn't wait for MPD's response and of course doesn't evaluate it. Therefore, the connection is in state "waiting for MPD reply", a state in which you can't send further commands.

The function mpd_response_finish(connection) waits for a response and checks if it is successful. Any payload data which may be present will be discarded; there are special functions for receiving the payload (mpd_recv_entity and others).

Simpler solution: use mpd_run_play(), which combines mpd_send_play() and mpd_response_finish(). Most _send_ functions have an equivalent _run_ function for convenience.

Re: mpd_connection_new() only works onces

Posted: October 19th, 2018, 9:09 am
by StefWe
Thank you very much for the detailed explanation.

Now I got what I did wrong.