我正在尝试在我的反应本机项目上播放视频。
已安装
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"
}
}
settings.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'
的build.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);
}
}
App.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
它也没有用。这个版本对我来说是怀疑的。
非常感谢任何帮助