使用的是gstreamer0.1, 想要判断当前播放的是不是jpeg/png图片, 现在的代码如下:
bool isImage(GstElement* playbin)
{
GstBin* bin = GST_BIN_CAST(playbin);
GstElement* typefind = gst_bin_get_by_name(bin, "typefind");
if (!typefind) {
printf("can't find typefind element"\n);
} else {
printf("find typefind element"\n);
}
GstPad* srcpad = gst_element_get_pad(typefind, "src");
GstCaps* caps = gst_pad_get_caps(srcpad);
GstStructure* structure = gst_caps_get_structure(caps, 0);
const gchar* name = gst_structure_get_name(structure);
if (strcmp(name, "image/jpeg") == 0 ||
strcmp(name, "image/png") == 0)
return true;
else
return false;
}
上面函数中,参数playbin是通过gst_element_factory_make("playbin", "play")产生的.
运行结果是使用gst_bin_get_by_name()返回值是NULL,导致后面的gstreamer函数都有问题.
所以想请教:
正确的从playbin中取得当前播放媒体的MIME类型的方法是什么?
playbin的管道是暂停之后才建立的,你先把管道暂停之后取得看看