Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A <Video /> component for react-native

License

NotificationsYou must be signed in to change notification settings

justhive/react-native-video

 
 

Repository files navigation

A<Video> component for react-native, as seen inreact-native-login!

Requires react-native >= 0.40.0, for RN support of 0.19.0 - 0.39.0 please use a pre 1.0 version.

Add it to your project

Runnpm i -S react-native-video

iOS

Runreact-native link to link the react-native-video library.

If you would like to allow other apps to play music over your video component, add:

AppDelegate.m

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

Note: you can also use theignoreSilentSwitch prop, shown below.

Android

Runreact-native link to link the react-native-video library.

Or if you have trouble, make the following additions to the given files manually:

android/settings.gradle

include':react-native-video'project(':react-native-video').projectDir=newFile(rootProject.projectDir,'../node_modules/react-native-video/android')

android/app/build.gradle

dependencies {...   compile project(':react-native-video')}

MainApplication.java

On top, where imports are:

importcom.brentvatne.react.ReactVideoPackage;

Add theReactVideoPackage class to your list of exported packages.

@OverrideprotectedList<ReactPackage>getPackages() {returnArrays.asList(newMainReactPackage(),newReactVideoPackage()    );}

Windows

Make the following additions to the given files manually:

windows/myapp.sln

Add theReactNativeVideo project to your solution.

  1. Open the solution in Visual Studio 2015
  2. Right-click Solution icon in Solution Explorer > Add > Existing Project...

UWP: Selectnode_modules\react-native-video\windows\ReactNativeVideo\ReactNativeVideo.csprojWPF: Selectnode_modules\react-native-video\windows\ReactNativeVideo.Net46\ReactNativeVideo.Net46.csproj

windows/myapp/myapp.csproj

Add a reference toReactNativeVideo to your main application project. From Visual Studio 2015:

  1. Right-click main application project > Add > Reference...

UWP: CheckReactNativeVideo from Solution Projects.WPF: CheckReactNativeVideo.Net46 from Solution Projects.

MainPage.cs

Add theReactVideoPackage class to your list of exported packages.

usingReactNative;usingReactNative.Modules.Core;usingReactNative.Shell;usingReactNativeVideo;// <-- Add thisusingSystem.Collections.Generic;...public override List<IReactPackage>Packages{get{return new List<IReactPackage>{newMainReactPackage(),newReactVideoPackage(),// <-- Add this};}}...

Usage

// 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.<Videosource={{uri:"background"}}// Can be a URL or a local file.ref={(ref)=>{this.player=ref}}// Store referencerate={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.playInBackground={false}// Audio continues to play when app entering background.playWhenInactive={false}// [iOS] Video continues to play when control or notification center are shown.ignoreSilentSwitch={"ignore"}// [iOS] ignore | obey - When 'ignore', audio will still play with the iOS hard silent switch set to silent. When 'obey', audio will toggle with the switch. When not specified, will inherit audio settings as usual.progressUpdateInterval={250.0}// [iOS] Interval to fire onProgress (default to ~250ms)onLoadStart={this.loadStart}// Callback when video starts to loadonLoad={this.setDuration}// Callback when video loadsonProgress={this.setTime}// Callback every ~250ms with currentTimeonEnd={this.onEnd}// Callback when playback finishesonError={this.videoError}// Callback when video cannot be loadedonBuffer={this.onBuffer}// Callback when remote video is bufferingonTimedMetadata={this.onTimedMetadata}// Callback when the stream receive some metadatastyle={styles.backgroundVideo}/>// Later to trigger fullscreenthis.player.presentFullscreenPlayer()// To set video position in seconds (seek)this.player.seek(0)// Later on in your styles..varstyles=StyleSheet.create({backgroundVideo:{position:'absolute',top:0,left:0,bottom:0,right:0,},});
    • For iOS you also need to specify muted for this to work

Android Expansion File Usage

// Within your render function, assuming you have a file called// "background.mp4" in your expansion file. Just add your main and (if applicable) patch version<Videosource={{uri:"background",mainVer:1,patchVer:0}}// Looks for .mp4 file (background.mp4) in the given expansion version.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 loadonLoad={this.setDuration}// Callback when video loadsonProgress={this.setTime}// Callback every ~250ms with currentTimeonEnd={this.onEnd}// Callback when playback finishesonError={this.videoError}// Callback when video cannot be loadedstyle={styles.backgroundVideo}/>// Later on in your styles..varstyles=Stylesheet.create({backgroundVideo:{position:'absolute',top:0,left:0,bottom:0,right:0,},});

Load files with the RN Asset System

The asset systemintroduced in RN0.14 allows loading image resources shared across iOS and Android without touching native code. As of RN0.31the same is true of mp4 video assets for Android. As ofRN0.33 iOS is also supported. Requiresreact-native-video@0.9.0.

<Video  repeat  resizeMode='cover'  source={require('../assets/video/turntable.mp4')}  style={styles.backgroundVideo}/>

Play in background on iOS

To enable audio to play in background on iOS the audio session needs to be set toAVAudioSessionCategoryPlayback. SeeApple documentation for additional details. (NOTE: there is now a ticket toexpose this as a prop )

Static Methods

seek(seconds)

Seeks the video to the specified time (in seconds). Access using a ref to the component

presentFullscreenPlayer()

Toggles a fullscreen player. Access using a ref to the component.

Examples

  • See anExample integration inreact-native-loginnote that this example uses an older version of this library, before we usedexport default -- if you userequire you will need to dorequire('react-native-video').default as per instructions above.

  • Try the includedVideoPlayer example yourself:

    git clone git@github.com:react-native-community/react-native-video.gitcd react-native-video/examplenpm installopen ios/VideoPlayer.xcodeproj

    ThenCmd+R to start the React Packager, build and run the project in the simulator.

  • Lumpen Radio contains another example integration using local files and full screen background video.

TODOS

  • Add support for captions
  • Add support for playing multiple videos in a sequence (will interfere with currentrepeat implementation)
  • Callback to get buffering progress for remote videos
  • Bring API closer to HTML5<Video>reference

MIT Licensed

About

A <Video /> component for react-native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java58.8%
  • Objective-C21.4%
  • JavaScript15.4%
  • C#3.2%
  • Other1.2%

[8]ページ先頭

©2009-2025 Movatter.jp