鸿蒙 视频播放开发(基础文,适合新人)
目录:
官方指导地址:https://developer.harmonyos.com/cn/docs/documentation/doc-guides/media-video-player-0000000000044178
关键步骤 1 player初始化
2,设置 Source; 视频播放的源(可以是本地,也可以是网络)
目前只研究到放文件在工程里
3,渲染到SurfaceProvider上
4,player的各种监听回调;
5,播放,暂停等
6,时间的更新,用的EventHandler
EventRunner runner = EventRunner.create(true);
timeHandler = new TimeHandler(runner);
sendTimeHandler();
private class TimeHandler extends EventHandler {
public TimeHandler(EventRunner runner) throws IllegalArgumentException {
super(runner);
}
@Override
protected void processEvent(InnerEvent event) {
super.processEvent(event);
if (event.eventId == 0) {
if (player != null && player.isNowPlaying()) {
int duration = player.getDuration();
int currentTime = player.getCurrentTime();
getUITaskDispatcher().syncDispatch(new Runnable() {
@Override
public void run() {
progressBar.setProgressValue(currentTime);
progressBar.setMaxValue(duration);
durationText.setText(DateUtils.msToString(duration));
currentTimeText.setText(DateUtils.msToString(currentTime));
}
});
}
}
sendTimeHandler();
}
}
private void sendTimeHandler() {
timeHandler.sendEvent(
0, 1000, EventHandler.Priority.IMMEDIATE);
}
作者:陈浩南xxx
想了解更多内容,请访问51CTO和华为合作共建的鸿蒙社区:https://harmonyos.51cto.com