ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Cound some body help?
I have that problem.
I start a sound calling:
ca_context_play (mContext, 2, CA_PROP_MEDIA_FILENAME, "MySound.wav", NULL);
If I call:
ca_context_playing(mContext,2,&_isPlaying);
_isPlaying is 1.
Then I call:
ca_context_cancel(mContext,2);
and the sound doesn't stops. But if I call again:
ca_context_playing(mContext,2,&_isPlaying);
_isPlaying is 0.
Hi norobro. Thank you very much for your fast response.
I've tested your code and it don't works.
I've added this line:
Code:
ca_context_create (&contx);
<-- your code
Code:
int ret;
if ((ret = ca_context_set_driver(contx, "alsa"))){
printf((char*)"error 0x%2.2x ",ret);
}
<-- line added
with this line the sound was played, but it didn't stop until the program is finnished. So
Code:
ca_context_cancel(contx, 1);
does noting.
This is my whole code:
Code:
#include <glib.h>
#include <canberra-gtk.h>
#include <stdio.h>
int main () {
int ret;
int isPlaying = 0;
ca_context * contx;
ca_context_create (&contx);
if ((ret = ca_context_set_driver(contx, "alsa"))){
printf((char*)"Error 0x%2.2X",ret);
}
ret = ca_context_play(contx, 1, CA_PROP_MEDIA_FILENAME,
"/home/SND/TEST.WAV", NULL);
if (ret) isPlaying = 1;
ca_context_playing(contx, 1, &isPlaying);
printf("%d\n", isPlaying);
usleep (750000);
ca_context_cancel(contx, 1);
usleep(1000000); // delay to make sure cancel works v. program termination
return 0; // with a breakpoint in this line sound never stops
}
int main () {
int ret;
int isPlaying = 0;
ca_context * contx;
ca_context_create (&contx);
if ((ret = ca_context_set_driver(contx, "alsa"))){
printf((char*)"Error 0x%2.2X",ret);
}
ret = ca_context_play(contx, 1, CA_PROP_MEDIA_FILENAME,
"/usr/share/sounds/alsa/Front_Center.wav", NULL);
if (ret) isPlaying = 1;
ret = ca_context_playing(contx, 1, &isPlaying);
printf("IsPlaying:%d ret:%d\n", isPlaying,ret);
usleep (750000);
ca_context_cancel(contx, 1);
ret = ca_context_playing(contx, 1, &isPlaying);
printf("IsPlaying:%d ret:%d\n", isPlaying,ret);
usleep(1000000); // delay to make sure cancel works v. program termination
return 0;
}
If you wanna test like me should :
-add these libpaths:
/usr/lib
/usr/lib/x86_64-linux-gnu
-add these libraries:
canberra
-and add these includes:
/usr/include
/usr/include/glib-2.0
/usr/lib/x86_64-linux-gnu/glib-2.0/include
/usr/include/gtk-3.0
/usr/include/pango-1.0
/usr/include/cairo
/usr/include/gdk-pixbuf-2.0
/usr/include/atk-1.0
Hi norobro.
I've checked it and you are rigth. With pulse it works fine. Thx
Keefaz.
If you look at my last code you'll see your 1st piece of code and the console output.
I can't use the 2nd one piece because if I have any other sound playing it will be stopped too. I only want to stop one sound.
Thx any way for your help.
All of you are so kind helping people.
Last edited by vampireixon; 04-13-2018 at 12:41 PM.
Reason: I've done more tests and them worked fine
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.