mpd_connection_new() only works onces

Discuss client development (or even MPD development if you feel so inclined), ask questions about the client libs, MPD feature requests from client developers, etc...
Post Reply
StefWe
Posts: 7
Joined: September 8th, 2018, 8:08 pm

mpd_connection_new() only works onces

Post by StefWe » October 18th, 2018, 9:15 pm

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.

max
Forum team
Posts: 781
Joined: January 15th, 2013, 3:43 pm

Re: mpd_connection_new() only works onces

Post by max » October 19th, 2018, 7:42 am

Which function?

StefWe
Posts: 7
Joined: September 8th, 2018, 8:08 pm

Re: mpd_connection_new() only works onces

Post by StefWe » October 19th, 2018, 8:30 am

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.

max
Forum team
Posts: 781
Joined: January 15th, 2013, 3:43 pm

Re: mpd_connection_new() only works onces

Post by max » October 19th, 2018, 8:54 am

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.

StefWe
Posts: 7
Joined: September 8th, 2018, 8:08 pm

Re: mpd_connection_new() only works onces

Post by StefWe » October 19th, 2018, 9:09 am

Thank you very much for the detailed explanation.

Now I got what I did wrong.

Post Reply