我想从我的qt小部件应用程序播放视频。由于Qt不支持Qmediaplayer在Android我不能使用它。另外由于某种原因,QML videooutput类型也不起作用。Qt C++如何通过android的本地播放器播放视频
因此,我想调用本机android视频播放器,以便当用户按下应用程序选择器启动的按钮时。我已经设立了这一部分。
我发现许多不同地方的信息,但无法弄清楚如何把所有东西放在一起。
其中启动应用程序选择器中的Java代码:
public class videoPlayer extends org.qtproject.qt5.android.bindings.QtActivity
{
private static videoPlayer instance;
videoPlayer() {
instance = this;
}
public void playVideo(String newVideoPath) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newVideoPath));
intent.setDataAndType(Uri.parse(newVideoPath), "video/*");
// Verify that the intent will resolve to an activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
String title = "play video with";
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(intent, title);
// Verify the original intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
}
}
的C++代码应该调用上面的Java方法
QAndroidJniObject videoUrl = QAndroidJniObject::fromString("file://path/to/video/1.mp4");
QAndroidJniObject::callStaticMethod<void>("path/to/java/src/videoPlayer",
"playVideo",
"(Ljava/lang/String;)V",
videoUrl.object<jstring>());
上述应启动选择器,但在我而言,它确实...没有什么,没有错误,没有应用程序选择器,没有警告,没有视频,没有任何东西。
因此,我怎么能在qt C++中调用android中的应用选择器并传递视频的url?
请创建在调用playVideo函数你的java文件调试输出(如'Log.Wtf(“这里”);'这将有助于找出错误所在 – Felix