本项目是基于开源项目fenster进行harmonyos化的移植和开发的,可以通过项目标签以及 github地址.
移植版本:v.0.0.2
方式一:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
……
}
方式二:
allprojects {
repositories {
mavenCentral()
}
}
implementation 'io.openharmony.tpc.thirdlib:fenster:1.0.1'
fenster是一款用SurfaceProvider和Player组合实现的自定义视频播放器,只需将组件放在xml中, 然后调用组件对应的接口就可以进行视频播放,具体如下:
<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"/>
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>
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型