鸿蒙开源组件——fenster视频播放器

jacksky
发布于 2021-12-24 17:03
浏览
0收藏

fenster

本项目是基于开源项目fenster进行OHOS化的移植和开发的,可以通过项目标签以及 github地址.

移植版本:v.0.0.2

项目介绍

项目名称:fenster视频播放器

所属系列:OHOS的第三方组件适配移植

功能:

  • 1.简易视频播放器功能 支持暂停和播放,播放进度显示,快进和快退功能
  • 2.标准播放器功能 支持 暂停播放,播放进度显示,快进和快退,音量调节,亮度调节等功能
  • 3.视频缩放 支持不同size的缩放
  • 4.开发者可以扩展Next和Pre键,实现自己想要的功能

项目移植状态:主功能【手势功能未移植】

调用差异:亮度调节功能使用有差异,具体见使用说明

原项目Doc地址:https://github.com/malmstein/fenster

编程语言:java

安装教程

方式一:

  • 1.下载fenster/library的har包library.har(位于output文件夹下)。
  • 2.启动 DevEco Studio,将下载的har包,导入工程目录“entry->libs”下。
  • 3.在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下jar包的引用。
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
       ……
    }​

方式二:

allprojects {
    repositories {
        mavenCentral()
       
    }
}
implementation 'io.openharmony.tpc.thirdlib:fenster:1.0.1'
  • 4.在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。

使用说明

fenster是一款用SurfaceProvider和Player组合实现的自定义视频播放器,只需将组件放在xml中, 然后调用组件对应的接口就可以进行视频播放,具体如下:

  • 1.简易播放器使用
  • 1.1添加view到AbilitySlice的layout文件中
     <com.malmstein.fenster.view.FensterVideoComponent
    ohos:id="$+id:play_video_texture"
    ohos:width="match_parent"
    ohos:height="match_parent"/>
    
    <com.malmstein.fenster.controller.SimpleMediaFensterPlayerController
    ohos:id="$+id:play_video_controller"
    ohos:width="match_parent"
    ohos:height="match_content"
    ohos:align_parent_bottom="true"/>​
  • 1.2 在java代码中设置播放的资源(支持本地流和远程流)和开始播放
private void bindViews() {
  textureView = (FensterVideoView) findComponentById(ResourceTable.Id_play_video_texture);
  fullScreenMediaPlayerController = (SimpleMediaFensterPlayerController) findComponentById(
          ResourceTable.Id_play_video_controller);
}
private void initVideo() {
  fullScreenMediaPlayerController.setVisibilityListener(this);//用于控制控制器的显示与隐藏
  textureView.setMediaController(fullScreenMediaPlayerController);
  textureView.setOnPlayStateListener(fullScreenMediaPlayerController);
}
@Override
public void onPostStart() {
  String localFile = null;
if (mIntent != null) {
    localFile = mIntent.getStringParam(KEY_LOCAL_FILE);
  }
if (localFile != null) {
    ohos.global.resource.ResourceManager resManager = getAbilityPackageContext().getResourceManager();
    RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/big_buck_bunny.mp4");
    RawFileDescriptor assetFileDescriptor;
try {
      assetFileDescriptor = rawFileEntry.openRawFileDescriptor();
      textureView.setVideo(assetFileDescriptor);//设置本地视频资源
    } catch (IOException e) {
      e.printStackTrace();
    }
  } else {
    textureView.setVideo("https://mos-vod-drcn.dbankcdn.cn/P_VT/video_injection/A91343E9D/v3/9AB0A7921049102362779584128/MP4Mix_H.264_1920x1080_6000_HEAAC1_PVC_NoCut.mp4");//设置网络URI
  }
  textureView.start();
}
  • 2.标准播放器的使用,标准播放器使用MediaFensterPlayerController和FensterVideoView结合使用, 比简易播放器多了亮度调节和音量调节功能;基本用法和简易播放器一致,但是亮度调节的需要额外调用 一个接口,如下: fullScreenMediaPlayerController.bindAbilitySliceToBrightnessBar(this) 将AbilitySlice作为上下文绑定到MediaFensterPlayerController中;

  • 3.视频缩放使用:

  • 3.1 增加属性配置: xmlns:app="http://schemas.huawei.com/res/tools"

  • 3.2 配置app:scaleType="crop"

    <DependentLayout
    ohos:height="200vp"
    ohos:width="300vp">
    <com.malmstein.fenster.view.FensterVideoComponent
    ohos:id="$+id:play_video_texture"
    ohos:width="match_parent"
    ohos:height="match_parent"
    app:scaleType="crop"/>
    
    <com.malmstein.fenster.controller.SimpleMediaFensterPlayerController
    ohos:id="$+id:play_video_controller"
    ohos:width="match_parent"
    ohos:height="match_content"
    ohos:align_parent_bottom="true"
    />
    </DependentLayout>
  • 4.手势暂不支持
  • 5.pre和next按钮需要使用者自己扩展,原作者的这一块的也没有进行支持;

效果演示

  • 简易播放器鸿蒙开源组件——fenster视频播放器-鸿蒙开发者社区
  • 标准播放器鸿蒙开源组件——fenster视频播放器-鸿蒙开发者社区

版本迭代

  • v1.0.0 项目初次提交
  • v1.0.1 更新maven引用

版本和许可信息

  • Apache Licence (c) Copyright 2016 David Gonzalez

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 

http://www.apache.org/licenses/LICENSE-2.0

 

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

 

fenster-master.zip 9.52M 48次下载
已于2021-12-24 17:03:43修改
收藏
回复
举报
回复
    相关推荐