Re: Embed movie player using mplayer - How to execute mplayer (fork?)



Sorry Paulo, I sent reply to one, first.

One quick gotcha is that argv contains a vector of all the command options. These are typically separated by spaces when typed on the command line. However, your example has the whole command as one option.
So put the wid to a std::string, widstring, and

      argv.push_back("mplayer");
      argv.push_back("-quiet");
      argv.push_back("-slave");
      argv.push_back("-idle");
      argv.push_back("-wid");
      argv.push_back(widstring);
      argv.push_back("/home/test.
avi");
      Glib::spawn_async_with_pipes(std::string("/usr/bin"),argv,Glib::SpawnFlags(0));

Personally, I'm using fork combined with execlp():
   int pid = fork();
   if(pid == 0)
   {
      std::stringstream filecommand;
      filecommand <<"file=\""<<filename<<"\"";
      int returncode = execlp("mplayer","mplayer","-slave","-quiet","-idle","-input",filecommand.str().c_str(),"-wid",wid.c_str(),fileToPlay.c_str(),NULL);
      if(returncode == -1)
         perror("error initializing.\n");
      else
         std::cout <<"mplayer finished running."<<std::endl;
      exit(0);  
   }

where filename is the name of my named pipe file serving to control mplayer.  wid, fileToPlay are both std::strings.
- Show quoted text -


On Mon, Aug 18, 2008 at 10:13 AM, Paulo Flabiano Smorigo <pfsmorigo gmail com> wrote:
Hi again,

I put the function spawn in my program but he gives me a "No such file or directory" error. I check the file and the path is right.

The code:

void Player::play(int wid)
{
    int in_fd, out_fd;

    sprintf(command, "mplayer -quiet -slave -idle -wid %d /home/test.avi", wid);
  
    std::vector<std::string> argv;
    argv.push_back(command);
   
    Glib::spawn_async_with_pipes("/usr/bin", argv, Glib::SpawnFlags(0), sigc::slot<void>(), NULL, &in_fd, &out_fd, NULL);
}

The error:

(test:8804): glibmm-CRITICAL **:
unhandled exception (type Glib::Error) in signal handler:
domain: g-exec-error-quark
code  : 8
what  : Failed to execute child process "mplayer -quiet -slave -idle -wid 60817444 /home/test.avi" (No such file or directory)

Anybody know what I'm doing wrong?

Thanks in advance...
P.F.Smorigo




On Mon, Aug 18, 2008 at 10:56, Paulo Flabiano Smorigo <pfsmorigo gmail com> wrote:
Hi Jens,

I saw this method but I couldn't found any example of use... I'm trying to implement using the api but it's hard to do so...

Anyone here have and example of  a "Spawning Processes" use?

Thanks!
P.F.Smorigo



On Mon, Aug 18, 2008 at 10:47, Jens Georg <mail jensge org> wrote:

> How can I execute mplayer in my program? I tried using fork but didn't
> work...
> When I create a graphic app I need a different aproach?
> And to be more complicated I need a solution that works on linux and
> windows... :'(

Glib provides an abstraction layer above the various OS process spawning
methods, have a look at

http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__Spawn.html


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]