!4479 新增获取URL缩略图

Merge pull request !4479 from caochuan/master
This commit is contained in:
openharmony_ci 2024-06-11 06:11:06 +00:00 committed by Gitee
commit 68ead4ae4c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 217 additions and 12 deletions

View File

@ -677,6 +677,7 @@ Note:If the text contains special characters, please escape them according to th
<filteritem type="filepath" name="code/BasicFeature/Notification/CustomCommonEvent/lib/CardEvent-1.0.0.hap" desc="Provided by code/BasicFeature/Notification/CustomCommonEvent"/>
<filteritem type="filepath" name="code/BasicFeature/Ads/OAIDSample/lib/ResetOAID-1.0.0.hap" desc="Provided by code/BasicFeature/Ads/OAIDSample"/>
<filteritem type="filepath" name="code/Solutions/Tools/FlipClock/lib/Brightness-1.0.0.hap" desc="Provided by code/Solutions/Tools/FlipClock"/>
<filteritem type="filepath" name="code/BasicFeature/Media/VideoPlay/entry/src/main/resources/rawfile/test.mp4" desc="Provided by code/BasicFeature/Media/VideoPlay"/>
<filteritem type="filepath" name="code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/media/compass.png" desc="Provided by code/BasicFeature/DeviceManagement/Sensor"/>
<filteritem type="filepath" name=" code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/media/select.png" desc="Provided by code/BasicFeature/DeviceManagement/Vibrator"/>

View File

@ -25,7 +25,9 @@
6.点击AudioTrack音轨列表选择框可以选择音轨进行切换;
7.点击左上角退出箭头,退出应用。
7.点击进入获取缩略图界面,可以获取视频的缩略图;
8.点击左上角退出箭头,退出应用。
### 目录结构
```

View File

@ -23,6 +23,7 @@ import emitter from '@ohos.events.emitter';
import { VideoPanel } from '../components/VideoPanel';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@kit.BasicServicesKit';
import { router } from '@kit.ArkUI';
const PROPORTION = 0.99; // 占屏幕比例
const SURFACEW = 0.9; // 表面宽比例
@ -211,7 +212,32 @@ struct Index {
}
.width('100%')
.justifyContent(FlexAlign.Start)
Row() {
Row() {
Button() {
Text($r('app.string.thumbnail_page'))
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.id('Thumbnail_1')
.type(ButtonType.Capsule)
.backgroundColor('#0D9FFB')
.width('60%')
.height('5%')
.onClick(() => {
router.pushUrl({
url: 'pages/ThumbnailGet'
}, router.RouterMode.Standard, (err) => {
if (err) {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
return;
}
console.info('pushUrl success');
});
})
}
.width('100%')
}
// 点击图标设置音频轨道
Select(this.avPlayManage.arrList)
.id('Select')

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 Hunan OpenValley Digital Industry Development Co., Ltd.
* 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.
*/
import media from '@ohos.multimedia.media'
import image from '@ohos.multimedia.image';
import fs from '@ohos.file.fs';
@Entry
@Component
struct Index {
@State pixelMap: PixelMap|undefined[] = [undefined, undefined, undefined, undefined, undefined]
@State diffTime: number[] = [0, 0, 0, 0, 0, 0]
build() {
Row() {
Column() {
Button() {
Text($r('app.string.get_thumbnail'))
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.id('Thumbnail_2')
.type(ButtonType.Capsule)
.backgroundColor('#0D9FFB')
.width('60%')
.height('5%')
.onClick(() => {
this.fetchFrameAndMeta()
})
Row() {
Image(this.pixelMap[0]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
Image(this.pixelMap[1]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
Image(this.pixelMap[2]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
}
Row() {
Text(this.diffTime[0].toString()).width(130).height(30)
Text(this.diffTime[1].toString()).width(130).height(30)
Text(this.diffTime[2].toString()).width(130).height(30)
}
Row() {
Image(this.pixelMap[3]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
Image(this.pixelMap[4]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
Image(this.pixelMap[5]).width(130).height(200).objectFit(ImageFit.Fill).margin({ top: 20 })
}
Row() {
Text(this.diffTime[3].toString()).width(130).height(30)
Text(this.diffTime[4].toString()).width(130).height(30)
Text(this.diffTime[5].toString()).width(130).height(30)
}
}
.width('100%')
}
.height('100%')
}
async fetchFrameAndMeta() {
let avFileDescriptor = await globalThis.getContext().resourceManager.getRawFd('test.mp4')
if (canIUse('SystemCapability.Multimedia.Media.AVMetadataExtractor')) {
let avMetadataExtractor = await media.createAVMetadataExtractor()
avMetadataExtractor.fdSrc = avFileDescriptor
let metadata = await avMetadataExtractor.fetchMetadata()
console.info(`winddraw rotation ${metadata.videoOrientation}`)
let duration = Number(metadata.duration)
this.diffTime[0] = 0
for (let i = 0; i < 4; i++) {
this.diffTime[i + 1] = this.diffTime[i] + duration / 5 * 1000
}
this.diffTime[5] = duration * 1000
avMetadataExtractor.release()
}
if (canIUse('SystemCapability.Multimedia.Media.AVImageGenerator')) {
let queryOption = media.AVImageQueryOptions.AV_IMAGE_QUERY_CLOSEST_SYNC
for (let i = 0; i < 6; i++) {
let avImageGenerator: media.AVImageGenerator = await media.createAVImageGenerator()
avImageGenerator.fdSrc = avFileDescriptor
this.pixelMap[i] = await avImageGenerator.fetchFrameByTime(this.diffTime[i], queryOption, {})
avImageGenerator.release()
}
}
}
savePixelMapData(pixelMap: PixelMap) {
pixelMap.getImageInfo().then((imageInfo: image.ImageInfo) => {
if (imageInfo == undefined) {
console.error('Failed to obtain the image pixel map information');
}
const readBuffer: ArrayBuffer = new ArrayBuffer(imageInfo.size.height * imageInfo.size.width * 4)
pixelMap.readPixelsToBuffer(readBuffer).then(() => {
let filePath = globalThis.getContext().filesDir + '/winddraw.dat';
let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
fs.writeSync(file.fd, readBuffer)
fs.closeSync(file)
}).catch(() => {
console.error('Failed to read image pixel data.');
})
})
}
}

View File

@ -75,6 +75,14 @@
{
"name": "track_name_1",
"value": "轨道:1"
},
{
"name": "thumbnail_page",
"value": "进入获取缩略图页面"
},
{
"name": "get_thumbnail",
"value": "获取缩略图(test.mp4)"
}
]
}

View File

@ -1,5 +1,6 @@
{
"src": [
"pages/Index"
"pages/Index",
"pages/ThumbnailGet"
]
}
}

View File

@ -75,6 +75,14 @@
{
"name": "track_name_1",
"value": "track:1"
},
{
"name": "thumbnail_page",
"value": "进入获取缩略图页面"
},
{
"name": "get_thumbnail",
"value": "获取缩略图(test.mp4)"
}
]
}

Binary file not shown.

View File

@ -75,6 +75,14 @@
{
"name": "track_name_1",
"value": "轨道:1"
},
{
"name": "thumbnail_page",
"value": "进入获取缩略图页面"
},
{
"name": "get_thumbnail",
"value": "获取缩略图(test.mp4)"
}
]
}

View File

@ -17,6 +17,7 @@ import { Driver, ON } from '@ohos.UiTest';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { getString } from '../utils/ResourceUtil';
import hilog from '@ohos.hilog';
import { router } from '@kit.ArkUI';
const TAG = '[Sample_VideoPlay]';
const DOMAIN = 0xF811;
@ -262,6 +263,37 @@ export default function abilityTest() {
hilog.info(DOMAIN, TAG, 'PlayPause_002 end');
})
/**
* 点击获取缩略图
*/
it('Thumbnail_001', 0, async (done: Function) => {
hilog.info(DOMAIN, TAG, 'Thumbnail_001 begin');
// 拉起操作界面
await driver.delayMs(8000);
await driver.assertComponentExist(ON.id('Video'));
let stack = await driver.findComponent(ON.id('Video'));
await stack.click();
// 点击进入获取缩略图界面
await driver.assertComponentExist(ON.id('Thumbnail_1'));
let thumbnailButton1 = await driver.findComponent(ON.id('Thumbnail_1'));
await thumbnailButton1.click();
// 点击获取缩略图
await driver.assertComponentExist(ON.id('Thumbnail_2'));
let thumbnailButton2 = await driver.findComponent(ON.id('Thumbnail_2'));
await thumbnailButton2.click();
await driver.delayMs(2000);
// 退回到视频播放页面
router.back(1)
await driver.delayMs(1000);
await stack.click();
done();
hilog.info(DOMAIN, TAG, 'Thumbnail_001 end');
})
/**
* 退出测试
*/

View File

@ -2,13 +2,14 @@
## 用例表
|测试功能|预置条件|输入|预期输出|测试结果|
|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|
|拉起应用|设备正常运行| 点击应用 |成功拉起应用|Pass|
|拉起操作面板|设备正常运行|点击视频界面|成功拉起操作面板|Pass|
|暂停、播放|在操作界面 | 1、点击**暂停**按钮<br>2、点击**继续**按钮 |1、视频暂停<br>2、视频播放|Pass|
|切换倍速|在操作界面 | 点击倍速选择2.0X | 倍速变为2.0X |Pass|
| 测试功能 |预置条件|输入|预期输出|测试结果|
|---|--------------------------------|------------------------------|------------------------|--------------------------------|
| 拉起应用 |设备正常运行| 点击应用 |成功拉起应用|Pass|
| 拉起操作面板 |设备正常运行|点击视频界面|成功拉起操作面板|Pass|
| 暂停、播放 |在操作界面 | 1、点击**暂停**按钮<br>2、点击**继续**按钮 |1、视频暂停<br>2、视频播放|Pass|
| 切换倍速 |在操作界面 | 点击倍速选择2.0X | 倍速变为2.0X |Pass|
| 切换视频 | 在操作界面 | 点击视频名选择test2视频 | 切换到test2视频 |Pass|
|视频跳转| 在操作界面 | 滑动滑动条 | 滑动后视频跳转到相应位置 |Pass|
| 视频跳转 | 在操作界面 | 滑动滑动条 | 滑动后视频跳转到相应位置 |Pass|
| 退出应用 | 在操作界面 | 点击左上角退出按钮 | 成功退出应用|Pass|
| 切换音轨 | 在操作界面 | 点击多音轨列表选项 | 成功切换音轨|Pass|
| 切换音轨 | 在操作界面 | 点击多音轨列表选项 | 成功切换音轨|Pass|
| 获取缩略图 | 在操作界面 | 点击进入获取缩略图界面并点击获取缩略图 | 成功获取缩略图|Pass|