我正在尝试在我的 react-native android 项目上播放视频。
已安装
react-native-video && react-native 链接
我不能玩local storage
和online videos
。
问题
- 有时音频仅与白屏一起出现。
- 有时视频闪烁。
包,json
{
"name": "viapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-video": "^2.0.0"
},
"devDependencies": {
"babel-jest": "23.0.0",
"babel-preset-react-native": "4.0.0",
"jest": "23.0.0",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
设置.gradle
rootProject.name = 'viapp'
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
include ':app'
构建.gradle
dependencies {
compile project(':react-native-video')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
MainApplication.java
package com.viapp;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.brentvatne.react.ReactVideoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
应用程序.js
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import Video from 'react-native-video';
import Dog from './dog.mp4';
import LightVideo from "./lights.mp4";
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Video
source={LightVideo}
resizeMode="cover"
style={StyleSheet.absoluteFill}
/>
</View>
);
}
}
// Later on in your styles..
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
我不知道我在哪里犯了错误。我试过uri
了也没有工作。这个版本对我来说是可疑的。
任何帮助将非常感激