本小节主要说明 HarmonyOS 车载多媒体的使用方法,以音乐 Demo 开发为例,开发步骤如下:
成都创新互联欢迎联系:18982081108,为您提供成都网站建设网页设计及定制高端网站建设服务,成都创新互联网页制作领域十载,包括成都水泥搅拌车等多个领域拥有丰富的网站制作经验,选择成都创新互联,为企业保驾护航!
super.setUIContent(ResourceTable.Layout_play_music_layout);
public class PlayManager {
...
private Player player;
public synchronized boolean play(String filePath, int startMilliSecond) {
...
FileDescriptor fd = IoUtil.getFileDescriptor(filePath);
Source source = new Source(fd);
player.setSource(source);
boolean isSuccess = player.prepare();
isSuccess = player.rewindTo(startMilliSecond * MICRO_MILLI_RATE, REWIND_NEXT_SYNC);
// 播放
isSuccess = player.play();
isPlaying.set(isSuccess);
return isSuccess;
}
public synchronized void pause(int startMilliSecond) {
...
player.pause();
}
public synchronized void stop() {
if (player == null) {
return;
}
player.stop();
isPlaying.set(false);
LogUtil.info(TAG, "stop success");
player.release();
player = null;
}
}
// 指定歌曲播放
String path = "/data/music/files/data/wonderful_life.mp3";
PlayManager.getInstance().play(path,1);
// 视频布局实现方法
public class MySurfaceSlice extends AbilitySlice {
...
public void makeSurfaceView() {
...
mySurfaceProvider = new SurfaceProvider(this);
adaptiveBoxLayoutSurfaceView.AdaptiveBoxLayout.LayoutConfig().addComponent(mySurfaceProvider);
}
}
public class VideoPlay {
public synchronized void startPlay() {
...
ret = playImpl.play();
}
public synchronized void preParePlay() {
...
ret = playImpl.prepare();
}
public synchronized void pausePlay() {
...
boolean pauseRet = playImpl.pause();;
}
public synchronized void setSourcePlay(String filePath) {
...
FileDescriptor fd = IoUtil.getFileDescriptor(filePath);
Source source = new Source(fd);
playImpl.setSource(source);
}
@Override
public synchronized void onStop() {
...
super.onStop();
}
}
// 调用视频播放类进行播放
String filePath = "/data/video/files/data/festival.mp4";
VideoPlay videoPlay = new VideoPlay()
videoPlay.setSourcePlay(filePath);
videoPlay.startPlay();
本文标题:创新互联鸿蒙OS教程:鸿蒙OS添加多媒体支持
文章地址:http://www.stwzsj.com/qtweb/news20/14220.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联