DaanDeMeyer / reproc

A cross-platform (C99/C++11) process library
MIT License
552 stars 65 forks source link

GUI for players not visible on Windows #90

Closed Suraj-Yadav closed 1 year ago

Suraj-Yadav commented 1 year ago

I am trying to call a video player from a C++ program, but no GUI shows up. Task Manager shows that player process is running. When ffplay is used, the debug output is shown in console, so I know that the process is at least running. Is there any option I forgot to use somewhere?

Sample code to reproduce issue

#include <iostream>
#include <reproc++/reproc.hpp>
#include <system_error>
#include <vector>

#define UTIL_RETURN_ON_ERROR(rexpr)                                            \
    {                                                                          \
        auto val = (rexpr);                                                    \
        if (val == std::errc::no_such_file_or_directory) {                     \
            std::cerr << "Program not found. Make sure it's available in PATH" \
                      << std::endl;                                            \
            return val.value();                                                \
        }                                                                      \
        if (val) {                                                             \
            std::cerr << "ERROR:" << __FILE__ << ":" << __LINE__               \
                      << ": While running `" << #rexpr                         \
                      << "`: " << val.message() << std::endl;                  \
            return val.value();                                                \
        }                                                                      \
    }

int main() {
    reproc::process playerProcess;
    const std::vector<std::string> playerCmds{
        "absolute path to mpv.exe",  // or "absolute path to ffplay.exe",
        "absolute path to sample.mkv"};
    UTIL_RETURN_ON_ERROR(playerProcess.start(playerCmds));

    UTIL_RETURN_ON_ERROR(playerProcess.wait(reproc::infinite).second);
}
ayeganov commented 1 year ago

@Suraj-Yadav You should look into the source - there is a config section for Windows that describes the behavior of windows.

Suraj-Yadav commented 1 year ago

@ayeganov Thank you for your suggestion. I did find about wShowWindow, and after editing this out, player GUI was visible. But now player window was not active, and required manual switching.

While searching for a way to make window active, I found about start command in cmd. This provided a straight forward solution, eliminating the need to change wShowWindow.

To force player GUI to open, change arguments to

const std::vector<std::string> playerCmds{
        "cmd", "/C",
        "absolute path to mpv.exe",  // or "absolute path to ffplay.exe",
        "absolute path to sample.mkv"};

To make sure that player GUI is active, change arguments to

const std::vector<std::string> playerCmds{
        "cmd", "/C", "start",
        "absolute path to mpv.exe",  // or "absolute path to ffplay.exe",
        "absolute path to sample.mkv"};