1.0.2 • Published 4 years ago

react-native-media-player-jm v1.0.2

Weekly downloads
17
License
Apache License 2....
Repository
github
Last release
4 years ago

react-native-media-player-jm npm version

Jimi Media Player SDK modules and view for React Native(iOS & Android(Not supported)), support react native 0.57+

Sample

Environments

  • JS

    • node: 8.0+
  • Android(Not currently supported)

    • Android SDK: api 28+

    • gradle: 4.5

    • Android Studio: 3.1.3+

  • iOS

    • XCode: 10.0+

    • iOS SDK:9.0+

Install Component

npm install react-native-media-player-jm --save

or

yarn add react-native-media-player-jm

Link Component

Android Studio

react-native link react-native-media-player-jm

Xcode

  • Way1

    react-native link react-native-media-player-jm

  • Way2

    Add the following content to Podfile of Project:

  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport', 
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', 
    'RCTAnimation'
  ]
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'react-native-media-player-jm', :podspec => '../node_modules/react-native-media-player-jm/react-native-media-player-jm.podspec'

API Description

Impot component

import { Platform, NativeModules, NativeEventEmitter } from 'react-native';
import { JMMeidaMonitor } from 'react-native-media-player-jm';
const { height, width } = Dimensions.get('window');
const {
  JMMediaPlayer
} = NativeModules;

JMMeidaMonitor

This is a video display view.

PropTypeDefaultDescription
imageimagenulldisplay view

JMMediaPlayer API

This is media player API manager.

MethodResult TypeResult ContentDescription
initializenullnullSDK initialize
deInitializenullnullSDK deinitialize
play(String url)PromiseSuccess:"",Fail:see ErrCode TablePlay RTSP or RTMP video stream
stopPromiseSuccess:"",Fail:see ErrCode TableStop video stream
isPlayingPromiseSuccess:true or false,Fail:see ErrCode TableIs the video playing?
startRecord(String path)PromiseSuccess:"",Fail:see ErrCode Tablestart record video stream,PS:Video needs to be playing
stopRecordPromiseSuccess:"",Fail:see ErrCode Tablestop record video stream
isRecordingPromiseSuccess:true or false,Fail:see ErrCode TableIs recording a video?
getRecordingDurationPromiseSuccess:Int,Fail:see ErrCode Tablerecording duration
snapshot(String path)PromiseSuccess:local img file path,Fail:see ErrCode Tablevideo snapshot
setMute(Bool mute)PromiseSuccess:"",Fail:see ErrCode Tableset video mute
getMutePromiseSuccess:true or false,Fail:see ErrCode Tableget video mute status
setDelayMaxTime(Float time)PromiseSuccess:"",Fail:see ErrCode TableSet the maximum time of pre-caching queue, default is 10s and range is 0~30s.

JMMediaPlayer Listener

This is media player status callback for listener.

Play Status

  • name:kOnMediaPlayerPlayStatus

  • Content:

    • status:Int,See table below
    • errCode:Int,See ErrCode table
    • errMsg:String,Error message
  • Usage:

    NativeEventEmitter(JMMediaPlayer).addListener(JMMediaPlayer.kOnMediaPlayerPlayStatus, (reminder) => {
         console.log(reminder);
    });
NameValueDescription
playStatusNone0Stateless, initial state.
playStatusPrepare1Ready to play the video.
playStatusStart2Video has started, or has been display.
playStatusStop3Video has stopped,active call stop Api will not reply.
playStatusFailed4Video failed to start play.

Record Status

  • name:kOnMediaPlayerRecordStatus
  • Content:
    • status:Int,See table below
    • filePath:String,Locally recorded video mp4 file.
    • errCode:Int,See ErrCode table
    • errMsg:String,Error message
NameValueDescription
recordStatusNone0Stateless, initial state.
recordStatusStart1Video recording has started.
recordStatusComplete2Video has been recorded.
recordStatusFailed3Video has failed to record.
recordStatusErrRecording4Video is being recorded and cannot start again.

Receive Frame Info

  • name:kOnMediaPlayerReceiveFrameInfo
  • Content:
    • videoWidth:Int
    • videoHeight:Int
    • videoBps:Int
    • audioBps:Int
    • timestamp:Int

ErrCode

ValueDescription
0No Error
-1Video stream url is invalid
-2path is invalid
-3Failed to open the url
-4Video playback was abnormally interrupted.
-300Did not start playing
-301Recording initialization failed
-302Recording in progress
-10000Component is not initialized, call initialize.
-10001Component's Monitor view is null.
-10002Failed to save image
-10003Failed to do snapshot

JS Example

https://github.com/JimiPlatform/react-native-media-player-jm/tree/master/example/App.js