使用 vidtry 的 Android 自定义媒体控制器
我想在我的 Android 应用程序中使用自定义媒体控制器,因此查看 vidtry 代码 (http://github.com/vidtry/vidtry/vidtry/vidtry)。 com/commonsguy/vidtry),尤其是 Player.java:
该示例运行良好。但我希望示例在应用程序启动时自动播放固定视频(因此我不想输入 URL)。 我补充说:
@Override
public void onResume() {
super.onResume();
address.setText("/sdcard/mydata/category/1/video_agkkr6me.mp4");
go.setEnabled(true);
onGo.onClick(go);
}
奇怪的是,如果我运行该应用程序,视频的音频会播放,但图像不会显示。其他一切都工作正常(进度条等)。我无法弄清楚手动单击启动按钮和程序化按钮之间的区别。我查看了代码,没有发现手动点击和编程点击之间可能出现任何差异。
我检查了是否有任何元素(尤其是表面)可能被隐藏,但事实并非如此。我什至尝试了
surface.setVisibility(View.INVISIBLE);
surface.setVisibility(View.VISIBLE);
以防重绘出现问题,但没有区别。
当我手动按下“开始”按钮时,视频图像确实显示,但只是在自动启动时不显示。
I want to use a custom media controller in my Android app and therefore looking at the vidtry code (http://github.com/commonsguy/vidtry), especially Player.java:
The sample works fine as it comes. But I want the sample to play the fixed video automatically on app startup (so I don't want to enter a URL).
I added:
@Override
public void onResume() {
super.onResume();
address.setText("/sdcard/mydata/category/1/video_agkkr6me.mp4");
go.setEnabled(true);
onGo.onClick(go);
}
Strange thing here is that if I run the app, the audio of the video plays but the image doesn't show. Everything else works fine (progress bar, etc.). I can't figure out the difference between the manual click on the go-button and the programmatic one. I looked at the code and didn't see any difference that might occur between manual and programmatic click.
I checked if any elements (esp. surface) might be hidden, but it's not. I even tried a
surface.setVisibility(View.INVISIBLE);
surface.setVisibility(View.VISIBLE);
in case of some issue with the redrawing, but no difference.
The video image does show when I manually hit the go button, but just not on start up automatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 onResume 时表面还没有准备好。实现 SurfaceHolder.Callback,然后从 surfaceCreated(SurfaceHolderholder) 启动视频可以解决该问题。
It seemed that the surface wasn't ready at onResume yet. Implementing SurfaceHolder.Callback and then starting the video from surfaceCreated(SurfaceHolder holder) solves the problem.