⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playeripc.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        prop = argv[2];        result = sscanf(argv[3], "%d", &index);        if(result)        {            result = hxembedded_window_get_entry_string_property(window, prop, index, &val, 0);        }                if(result)        {            send_reply(channel, "%d, \"%s\"", HXR_OK, val);            g_free(val);        }        else        {            send_reply(channel, "%d, \"\"", HXR_FAIL);        }    }    else if (strcmp("Play", argv[0]) == 0 && argc == 2)    {        hxembedded_window_play(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("Seek", argv[0]) == 0 && argc == 3)    {        guint pos;        result = sscanf(argv[2], "%d", &pos);                    if(result)        {            hxembedded_window_start_seeking(window);            hxembedded_window_stop_seeking(window, pos);            send_reply(channel, "%d", HXR_OK);        }        else        {            send_reply(channel, "%d", HXR_FAIL);        }    }    else if (strcmp("PlayPause", argv[0]) == 0 && argc == 2)    {        HXContentStateType state;                    state = hxembedded_window_get_content_state(window);        switch(state)        {            case HX_CONTENT_STATE_STOPPED:             case HX_CONTENT_STATE_PAUSED:            case HX_CONTENT_STATE_NOT_LOADED:                hxembedded_window_play(window);                break;            case HX_CONTENT_STATE_PLAYING:            case HX_CONTENT_STATE_BUFFERING:                hxembedded_window_pause(window);                break;            default:                result = FALSE;                break;        }                send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else if (strcmp("Pause", argv[0]) == 0 && argc == 2)    {        hxembedded_window_pause(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("Stop", argv[0]) == 0 && argc == 2)    {        hxembedded_window_stop(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("Suspend", argv[0]) == 0 && argc == 2)    {        // XXXRGG: What's suspend supposed to do?        hxembedded_window_pause(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("Resume", argv[0]) == 0 && argc == 2)    {        hxembedded_window_play(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("UnsetWindow", argv[0]) == 0 && argc == 2)    {        result = hxembedded_window_unset_window(window);        send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("SetXID", argv[0]) == 0 && argc == 12)    {        XID xid;                    /* SetWindow passes us various dimensions.           The player will figure them out from the XID, though,           so we ignore them. */        result = sscanf(argv[2], "%d", (int*)&xid);        if(result)        {            result = hxembedded_window_set_window(window, xid, 0);        }                send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else if (strcmp("SetWindow", argv[0]) == 0 && argc == 12)    {        guint socket_id;                    result = sscanf(argv[2], "%d", &socket_id);                    if(result)        {            result = hxembedded_window_set_window(window, 0, socket_id);        }                send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else if (strcmp("NewStream", argv[0]) == 0 && argc == 6)    {        gchar* mime_type;        gchar* url;        guint stream_id;        guint stream_length;                result = sscanf(argv[2], "%d", &stream_id);        url = argv[3];        mime_type = argv[4];        result = sscanf(argv[5], "%d", &stream_length);        /* If stream_id is 0, mozilla has called the plugin's NewStream method           because it has encountered a <embed> tag. The plugin will abort this           stream by returning NPERR_NO_DATA, but it still calls this method           with stream as NULL in order to give us the content and mime type.           We will use this content and mime type later when we start playback           through a GetURL call. */                if(stream_id)        {            hxembedded_window_new_stream(window, stream_id, url, mime_type, stream_length);        }        else        {            hxembedded_window_set_src_url(window, url);        }                send_reply(channel, "%d", HXR_OK);    }    else if (strcmp("StreamData", argv[0]) == 0 && argc == 4)    {        gchar* buf;        guint buf_len;        guint stream_id;                result = sscanf(argv[2], "%d", &stream_id);        if(result)        {            result = sscanf(argv[3], "%d", &buf_len);        }        if(result && buf_len > 0)        {            buf = (gchar*)g_try_malloc(buf_len + 1);            result = (buf != NULL);                        if(result)            {                /* Give the plugin a 1000 ms inactivity timeout */                result = recv_with_timeout(channel, buf, buf_len, 1000);                buf[buf_len] = '\0';            }                        if(result)            {                hxembedded_window_stream_data(window, stream_id, (gchar*)buf, buf_len);            }            g_free(buf);        }                send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else if (strcmp("StreamDone", argv[0]) == 0 && argc == 3)    {        guint stream_id;                result = sscanf(argv[2], "%d", &stream_id);        hxembedded_window_stream_done(window, stream_id);                        send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else if (strcmp("SetStream", argv[0]) == 0 && argc == 4)    {        g_warning("Deprecated command SetStream called");        send_reply(channel, "%d", HXR_FAIL);    }    else if (strcmp("Browser", argv[0]) == 0 && argc == 5)    {        const gchar* user_agent;        gint has_callbacks;        gint has_xembed;        user_agent = argv[2];                        result = sscanf(argv[3], "%d", &has_callbacks);        if(result)        {            result = sscanf(argv[4], "%d", &has_xembed);        }        if(result)        {            hxembedded_window_set_browser_info(window,                                               user_agent,                                               has_callbacks,                                               has_xembed);        }                send_reply(channel, "%d", result? HXR_OK: HXR_FAIL);    }    else    {                send_reply(channel, "%d", HXR_FAIL);                                result = FALSE;    }            return result;}/* Returns whether or not the command parsed correctly. */gbooleanplayeripc_handle_command(GIOChannel *channel, const char *command){    gchar** argv;    gint argc = 0;    GError *error = NULL;    gboolean parse_result;    gboolean ret = TRUE;        parse_result = g_shell_parse_argv(command, &argc, &argv, &error);    if(error)    {        g_warning(error->message);        g_free(error);        return FALSE;    }        g_return_val_if_fail(parse_result, FALSE);        if(strcmp("Embed", argv[0]) == 0)    {        HXEmbeddedWindowAttributes attr;        window_attributes_set_defaults(&attr);        window_attributes_get_from_args(&attr, &argv[1]);        guint window_id = hxembedded_window_attach(&attr);        	send_reply(channel, "%d", window_id);    }    else if(strcmp("Version", argv[0]) == 0)    {        guint plugin_ipc_version = 0;        sscanf(argv[1], "%d", &plugin_ipc_version);        if(plugin_ipc_version > PLAYER_IPC_VERSION)        {            g_warning("plugin version %d > player version %d",                      plugin_ipc_version, PLAYER_IPC_VERSION);        }        	send_reply(channel, "%d, %d", HXR_OK, PLAYER_IPC_VERSION);    }    else if(strcmp("Shutdown", argv[0]) == 0)    {	send_reply(channel, "%d", HXR_OK);        // XXXRGG: be more graceful        gtk_main_quit();    }    else    {        /* Get the window id from argv[1] */        guint window_id;        HXEmbeddedWindow* window;        if(sscanf(argv[1], "%d", &window_id))        {                    window = hxembedded_window_get_from_id(window_id);            if(window)            {                ret = handle_window_command(window, channel, argc, argv);            }            else            {                g_warning("Bad window id %d", window_id);            }        }        else        {            g_warning("Bad window id \"%s\"", argv[1]);        }    }        g_strfreev(argv);    if(!ret)    {        g_warning("Error parsing command \"%s\"", command);    }    return ret;}voidplayeripc_get_url(HXEmbeddedWindow* window, const gchar* url, const gchar* target){    gchar* cmd;    guint window_id;    g_return_if_fail(url != NULL);        if(!target)    {        target = "\"\"";    }        window_id = hxembedded_window_get_id(window);        cmd = g_strdup_printf("GetURL %d \"%s\" %s\n", window_id, url, target);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));    g_free(cmd);}/* Javascript callbacks */voidplayeripc_on_author_change(HXEmbeddedWindow* window,                           const gchar*      /* unused */,                           GValue*           author_value){    gchar* cmd;    const gchar* author_name = g_value_get_string(author_value);    const gchar* name;    name = hxembedded_window_get_name(window);        gchar* author_name_quoted;    author_name_quoted = g_shell_quote(author_name);        cmd = g_strdup_printf("Callback %s OnAuthorChange %s\n",                          name, author_name_quoted);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));    g_free(cmd);    g_free(author_name_quoted);}voidplayeripc_on_buffering(HXEmbeddedWindow*    window,                       HXBufferingReason    reason,                       guint                percent_complete){    gchar *cmd;    const gchar* name;    name = hxembedded_window_get_name(window);        cmd = g_strdup_printf("Callback %s OnBuffering %d,%d\n",                          name, (int)reason, percent_complete);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));    g_free(cmd);}voidplayeripc_on_clip_closed(HXEmbeddedWindow* window){    gchar *cmd;    const gchar* name;    name = hxembedded_window_get_name(window);        cmd = g_strdup_printf("Callback %s OnClipClosed\n",                          name);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));    g_free(cmd);}voidplayeripc_on_clip_opened(HXEmbeddedWindow* window,                         const gchar*      short_clip_name,                         const gchar*      url){    gchar *cmd;    const gchar* name;    name = hxembedded_window_get_name(window);    gchar* short_clip_name_quoted = g_shell_quote(short_clip_name);    gchar* url_quoted = g_shell_quote(url);            cmd = g_strdup_printf("Callback %s OnClipOpened %s,%s\n",                          name, short_clip_name_quoted, url_quoted);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));        g_free(cmd);    g_free(short_clip_name_quoted);    g_free(url_quoted);}voidplayeripc_on_contacting(HXEmbeddedWindow* window,                        const gchar*      contacting_text){    gchar *cmd;    gchar* contacting_text_quoted = g_shell_quote(contacting_text);        const gchar* name;    name = hxembedded_window_get_name(window);        cmd = g_strdup_printf("Callback %s OnContacting %s\n",                          name, contacting_text_quoted);    send_ipc(g_playeripc.embedded_callbacks_channel, cmd, strlen(cmd));        g_free(cmd);    g_free(contacting_text_quoted);}voidplayeripc_on_copyright_change(HXEmbeddedWindow* window,                              const char* /* unused */,                              GValue* copyright_value){    gchar *cmd;    const gchar* name;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -