RN 下视频播放器的学习笔记 react-native-video

1,主要使用了react-native-video 开源库

下面开车

react-native-video 使用方法
1.到项目根目录:
npm i -S react-native-video
react-native link以链接react-native-video库。
以上完成Android 平台自动链接原生库

2 ios

AppDelegate.m中添加

#import <AVFoundation/AVFoundation.h>  // import
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];  // allow
  ...
}

app.js

import Video from 'react-native-video'
export default class App extends Component<Props> {
  render() {
    return (
        <Video
            ref={(ref) => {
                this.video = ref
            }}
            //来自本地的MP4视频
            source={require('./video/test.mp4')}
            //1.0表示默认速率
            rate={1.0}
            //图片等比例缩放
            resizeMode='contain'
            //不重复播放
            repeat={true}
            //默认音量
            volume={1.0}
            //样式
            style={styles.container}/>


    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

中途遇到很多问题
例如RN版本问题
yarn add react-native-cli
react-native init myApp –version 0.53.0
部分问题参考此大佬的博客:https://www.jianshu.com/p/7e4618edc70f

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值