[MPlayer-users] Invoking mplayer from a C program using linux system()

Anna Klein aklein at bluenotenetworks.com
Fri Feb 9 18:04:54 CET 2007


Hi mplayer users,

I've written a C program, running on linux, to invoke mplayer to play an
audio stream from the Internet, by using the system() call.  Is there
anyway to get a return status from mplayer?  

Suppose, for example, the URL is incorrect or the streaming server is
down, is there a way for my program to find out?

The return value of system() seems to return successfully regardless of
what happens with mplayer.

Thanks,
Anna


Here's the snippet of code where I invoke mplayer:

int startMplayer(char *addr)
{
    char cmdBuf[256];
    int  rc;

    rc = mkfifo(fifo_name, 0777);
    if ((0 == rc) || (EEXIST == errno))
    {
        printf("Created %s, now start mplayer\n", fifo_name);
        sprintf(cmdBuf, 
                "/usr/local/bin/mplayer %s -srate %d -noconsolecontrols
-quiet -vc null -vo null -ao pcm:fast:file=%s < /dev/null &", 
                (char *)addr, RATE, fifo_name);

        rc = system(cmdBuf);
        if (-1 == rc)
        {
            printf("startMplayer: Error starting up mplayer!\n");
        }
    }
    else
    {
        printf("Error %d creating %s!\n", fifo_name, errno);
    }

    return rc;
}





More information about the MPlayer-users mailing list