Template version: v0.2.0
react-native-create-thumbnail
[!TIP] GitHub address
Find the matching version information in the release address of a third-party library:@react-native-oh-tpl/react-native-create-thumbnail Releases.For older versions that are not published to npm, please refer to the installation guide to install the tgz package.
Go to the project directory and execute the following instruction:
npm install @react-native-oh-tpl/react-native-create-thumbnail
yarn add @react-native-oh-tpl/react-native-create-thumbnail
The following code shows the basic use scenario of the repository:
[!WARNING] The name of the imported repository remains unchanged.
import React, {useState } from 'react';
import { StyleSheet, Text, Button ,ScrollView,View} from 'react-native';
import { createThumbnail } from 'react-native-create-thumbnail';
export default function CreateThumbnailDemo() {
const [text, setText] = useState('');
const CreateThumbnail = async()=> {
let obj = await createThumbnail({
url:'https://media.w3.org/2010/05/sintel/trailer.mp4',
timeStamp: 10000
});
setText(JSON.stringify(obj))
}
return (
<View style={styles.container}>
<View style={styles.titleArea}>
<Text style = {styles.title}>Math</Text>
</View>
<View style = {styles.inputArea}>
<Text style={styles.baseText}>
{text}
</Text>
</View>
<ScrollView style={styles.scrollView}>
<View style={ { flexDirection: 'column'}}>
<View style ={styles.baseArea}>
<Text style= {{flex:1}}>createThumbnail</Text>
<Button title='Running' color='#841584' onPress={CreateThumbnail}></Button>
</View>
</View>
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
flexDirection: 'column',
alignItems: 'center',
backgroundColor: '#F1F3F5',
},
baseText: {
fontWeight: 'bold',
textAlign:'center',
fontSize:16
},
titleArea:{
width:'90%',
height:'8%',
alignItems:'center',
flexDirection:'row',
},
title: {
width:'90%',
color:'#000000',
textAlign:'left',
fontSize: 30,
},
scrollView: {
width:'90%',
marginHorizontal: 20,
},
inputArea: {
width:'90%',
height:'30%',
borderWidth:2,
borderColor:'#000000',
marginTop:8,
justifyContent:'center',
alignItems:'center',
},
baseArea: {
width:'100%',
height:60,
borderRadius:4,
borderColor:'#000000',
marginTop:8,
backgroundColor:'#FFFFFF',
flexDirection: 'row',
alignItems:'center',
paddingLeft:8,
paddingRight:8
}
});
Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking.
Open the harmony
directory of the HarmonyOS project in DevEco Studio.
{
...
"overrides": {
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
}
}
Currently, two methods are available:
Method 1 (recommended): Use the HAR file.
[!TIP] The HAR file is stored in the
harmony
directory in the installation path of the third-party library.
Open entry/oh-package.json5
file and add the following dependencies:
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
"@react-native-oh-tpl/react-native-create-thumbnail": "file:../../node_modules/@react-native-oh-tpl/react-native-create-thumbnail/harmony/createThumbnail.har"
}
Click the sync
button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm install
Method 2: Directly link to the source code.
[!TIP] The source code is located in the harmony folder within the installation path of the third-party library.
Open entry/oh-package.json5
file and add the following dependencies:
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
"@react-native-oh-tpl/react-native-create-thumbnail": "file:../../node_modules/@react-native-oh-tpl/react-native-create-thumbnail/harmony/createThumbnail"
}
run the following instruction on the terminal:
cd entry
ohpm install --no-link
Open the entry/src/main/ets/RNPackagesFactory.ts
file and add the following code:
...
+ import { CreateThumbnailPackage } from '@react-native-oh-tpl/react-native-create-thumbnail/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
new SamplePackage(ctx),
+ new CreateThumbnailPackage(ctx)
];
}
Click the sync
button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm install
Then build and run the code.
To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
Check the release version information in the release address of the third-party library: @react-native-oh-tpl/react-native-create-thumbnail Releases
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | Type | Required | HarmonyOS Support |
---|---|---|---|---|
createThumbnail | thumbnail generator with storage/cache management and support for both local and remote videos | function | NO | yes |
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
url | Path to video file (local or remote) | String | yes | Android/ios | yes |
timeStamp | Thumbnail timestamp (in milliseconds) | Number | NO | Android/ios | yes |
format | Thumbnail format, can be one of: jpeg, or png | String | NO | Android/ios | yes |
dirSize | Maximum size of the cache directory (in megabytes). When this directory is full, the previously generated thumbnails will be deleted to clear about half of it's size. | Number | NO | Android/ios | yes |
headers | Headers to load the video with. e.g. { Authorization: 'someAuthToken' } | Object | NO | Android/ios | yes |
cacheName | Cache name for this thumbnail to avoid duplicate generation. If specified, and a thumbnail already exists with the same cache name, it will be returned instead of generating a new one. | String | NO | Android/ios | yes |
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
path | Path to generated thumbnail | String | NO | Android/ios | yes |
size | Size (in bytes) of thumbnail | Number | NO | Android/ios | yes |
mime | Mimetype of thumbnail | String | NO | Android/ios | yes |
width | Thumbnail width | Number | NO | Android/ios | yes |
height | Thumbnail height | Number | NO | Android/ios | yes |
This project is licensed under The MIT License (MIT).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。