React Native开源播放器Video组件(react-native-video)

本文来自:江清清的技术专栏-翻译组(http://www.lcode.org)

开源项目地址:https://github.com/brentvatne/react-native-login

项目介绍

该组件进行封装成React Native平台播放器Video组件,大家可以使用该组件进行播放视频啦~不过支持React Native的版本最低0.19版本。

刚创建的React Native交流5群:386216878,欢迎各位大牛,React Native技术爱好者加入交流!

配置安装

1.1.运行命令进行安装

?
1
npm install react - native - video --save

1.2.iOS版本

以上的命令运行完成安装组件之后,如果你需要其他的应用也可以在你的Video组件上面播放音乐,视频等。你可以在AppDelegate.m文件作如下处理:

?
1
2
3
4
5
6
7
8
#import <AVFoundation/AVFoundation.h>  // import
 
- ( BOOL ) application : ( UIApplication * ) application didFinishLaunchingWithOptions : ( NSDictionary * ) launchOptions
{
   ...
   [[AVAudioSession sharedInstance] setCategory : AVAudioSessionCategoryAmbient error : nil];  / / allow
   ...
}

1.3.Android版本

首先复制你的Video文件到android项目的 android/app/src/main/res/raw/的文件夹中,然后做如下相关处理:

1.4.android/settings.gradle文件

?
1
2
include ':RCTVideo' , ':app'
project( ':RCTVideo' ).projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android' )

1.5.android/app/build.gradle文件

?
1
2
3
4
dependencies {
    ...
    compile project( ':RCTVideo' )
}

1.6.MainActivity.java文件修改

首先在文件的头部,导入相关包:

?
1
import com.brentvatne.react.ReactVideoPackage;

然后在方法中添加:

?
1
.addPackage( new ReactVideoPackage())
使用实例
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Within your render function, assuming you have a file called
// "background.mp4" in your project. You can include multiple videos
// on a single screen if you like.
<Video source={{uri: "background" }} // Can be a URL or a local file.
        rate={1.0}                   // 0 is paused, 1 is normal.
        volume={1.0}                 // 0 is muted, 1 is normal.
        muted={ false }                // Mutes the audio entirely.
        paused={ false }               // Pauses playback entirely.
        resizeMode= "cover"           // Fill the whole screen at aspect ratio.
        repeat={ true }                // Repeat forever.
        onLoadStart={ this .loadStart} // Callback when video starts to load
        onLoad={ this .setDuration}    // Callback when video loads
        onProgress={ this .setTime}    // Callback every ~250ms with currentTime
        onEnd={ this .onEnd}           // Callback when playback finishes
        onError={ this .videoError}    // Callback when video cannot be loaded
        style={styles.backgroundVideo} />
 
// Later on in your styles..
var styles = StyleSheet.create({
   backgroundVideo: {
     position: 'absolute' ,
     top: 0,
     left: 0,
     bottom: 0,
     right: 0,
   },
});

关于更多例子,大家可以去https://github.com/brentvatne/react-native-login  下载实例使用

运行效果:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值