Skip to content

Commit 625d765

Browse files
author
NghiNV
committedAug 12, 2018
fist commit
0 parents  commit 625d765

34 files changed

+3382
-0
lines changed
 

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Brent Vatne, Baris Sencan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎VLCPlayer.js

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
import React, { PureComponent } from 'react';
2+
import {
3+
StyleSheet,
4+
requireNativeComponent,
5+
NativeModules,
6+
View
7+
} from 'react-native';
8+
import PropTypes from 'prop-types';
9+
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
10+
11+
export default class VLCPlayer extends PureComponent {
12+
constructor(props, context) {
13+
super(props, context);
14+
this.seek = this.seek.bind(this);
15+
this.resume = this.resume.bind(this);
16+
this.snapshot = this.snapshot.bind(this);
17+
this._assignRoot = this._assignRoot.bind(this);
18+
this._onError = this._onError.bind(this);
19+
this._onProgress = this._onProgress.bind(this);
20+
this._onEnded = this._onEnded.bind(this);
21+
this._onPlaying = this._onPlaying.bind(this);
22+
this._onStopped = this._onStopped.bind(this);
23+
this._onPaused = this._onPaused.bind(this);
24+
this._onBuffering = this._onBuffering.bind(this);
25+
this._onOpen = this._onOpen.bind(this);
26+
this._onLoadStart = this._onLoadStart.bind(this);
27+
}
28+
29+
setNativeProps(nativeProps) {
30+
this._root.setNativeProps(nativeProps);
31+
}
32+
33+
seek(pos) {
34+
this.setNativeProps({ seek: pos });
35+
}
36+
37+
resume(isResume) {
38+
this.setNativeProps({ resume: isResume });
39+
}
40+
41+
snapshot(path) {
42+
this.setNativeProps({ snapshotPath: path });
43+
}
44+
45+
_assignRoot(component) {
46+
this._root = component;
47+
}
48+
49+
_onBuffering(event) {
50+
if (this.props.onBuffering) {
51+
this.props.onBuffering(event.nativeEvent);
52+
}
53+
}
54+
55+
_onError(event) {
56+
if (this.props.onError) {
57+
this.props.onError(event.nativeEvent);
58+
}
59+
}
60+
61+
_onOpen(event) {
62+
if (this.props.onOpen) {
63+
this.props.onOpen(event.nativeEvent);
64+
}
65+
}
66+
67+
_onLoadStart(event) {
68+
if (this.props.onLoadStart) {
69+
this.props.onLoadStart(event.nativeEvent);
70+
}
71+
}
72+
73+
_onProgress(event) {
74+
if (this.props.onProgress) {
75+
this.props.onProgress(event.nativeEvent);
76+
}
77+
}
78+
79+
_onEnded(event) {
80+
if (this.props.onEnd) {
81+
this.props.onEnd(event.nativeEvent);
82+
}
83+
}
84+
85+
_onStopped(event) {
86+
this.setNativeProps({ paused: true });
87+
if (this.props.onStopped) {
88+
this.props.onStopped(event.nativeEvent);
89+
}
90+
}
91+
92+
_onPaused(event) {
93+
if (this.props.onPaused) {
94+
this.props.onPaused(event.nativeEvent);
95+
}
96+
}
97+
98+
_onPlaying(event) {
99+
if (this.props.onPlaying) {
100+
this.props.onPlaying(event.nativeEvent);
101+
}
102+
}
103+
104+
render() {
105+
/* const {
106+
source
107+
} = this.props;*/
108+
const source = resolveAssetSource(this.props.source) || {};
109+
110+
let uri = source.uri || '';
111+
if (uri && uri.match(/^\//)) {
112+
uri = `file://${uri}`;
113+
}
114+
115+
let isNetwork = !!(uri && uri.match(/^https?:/));
116+
const isAsset = !!(uri && uri.match(/^(assets-library|file|content|ms-appx|ms-appdata):/));
117+
if (!isAsset) {
118+
isNetwork = true;
119+
}
120+
source.initOptions = source.initOptions || [];
121+
//repeat the input media
122+
source.initOptions.push('--input-repeat=1000');
123+
const nativeProps = Object.assign({}, this.props);
124+
Object.assign(nativeProps, {
125+
style: [styles.base, nativeProps.style],
126+
source: source,
127+
src: {
128+
uri,
129+
isNetwork,
130+
isAsset,
131+
type: source.type || '',
132+
mainVer: source.mainVer || 0,
133+
patchVer: source.patchVer || 0,
134+
},
135+
onVideoLoadStart: this._onLoadStart,
136+
onVideoOpen: this._onOpen,
137+
onVideoError: this._onError,
138+
onVideoProgress: this._onProgress,
139+
onVideoEnded: this._onEnded,
140+
onVideoEnd: this._onEnded,
141+
onVideoPlaying: this._onPlaying,
142+
onVideoPaused: this._onPaused,
143+
onVideoStopped: this._onStopped,
144+
onVideoBuffering: this._onBuffering,
145+
progressUpdateInterval: 250,
146+
});
147+
148+
return <RCTVLCPlayer ref={this._assignRoot} {...nativeProps} />;
149+
}
150+
}
151+
152+
VLCPlayer.propTypes = {
153+
/* Native only */
154+
rate: PropTypes.number,
155+
seek: PropTypes.number,
156+
resume: PropTypes.bool,
157+
snapshotPath: PropTypes.string,
158+
paused: PropTypes.bool,
159+
160+
videoAspectRatio: PropTypes.string,
161+
volume: PropTypes.number,
162+
disableFocus: PropTypes.bool,
163+
src: PropTypes.string,
164+
playInBackground: PropTypes.bool,
165+
playWhenInactive: PropTypes.bool,
166+
resizeMode: PropTypes.string,
167+
poster: PropTypes.string,
168+
repeat: PropTypes.bool,
169+
muted: PropTypes.bool,
170+
171+
172+
onVideoLoadStart: PropTypes.func,
173+
onVideoError: PropTypes.func,
174+
onVideoProgress: PropTypes.func,
175+
onVideoEnded: PropTypes.func,
176+
onVideoPlaying: PropTypes.func,
177+
onVideoPaused: PropTypes.func,
178+
onVideoStopped: PropTypes.func,
179+
onVideoBuffering: PropTypes.func,
180+
onVideoOpen: PropTypes.func,
181+
182+
/* Wrapper component */
183+
source: PropTypes.object,
184+
185+
onError: PropTypes.func,
186+
onProgress: PropTypes.func,
187+
onEnded: PropTypes.func,
188+
onStopped: PropTypes.func,
189+
onPlaying: PropTypes.func,
190+
onPaused: PropTypes.func,
191+
192+
/* Required by react-native */
193+
scaleX: PropTypes.number,
194+
scaleY: PropTypes.number,
195+
translateX: PropTypes.number,
196+
translateY: PropTypes.number,
197+
rotation: PropTypes.number,
198+
...View.propTypes,
199+
};
200+
201+
const styles = StyleSheet.create({
202+
base: {
203+
overflow: 'hidden',
204+
},
205+
});
206+
const RCTVLCPlayer = requireNativeComponent('RCTVLCPlayer', VLCPlayer);

‎android/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion '25.0.0'
6+
7+
defaultConfig {
8+
minSdkVersion 16
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
ndk {
13+
abiFilters 'armeabi-v7a'//,'x86_64','arm64-v8a','x86'
14+
}
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
provided fileTree(dir: 'libs', include: ['*.jar'])
26+
compile "com.facebook.react:react-native:+"
27+
compile 'com.yyl.vlc:vlc-android-sdk:3.0.10'
28+
}

‎android/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/aolc/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package react.yuanzhou.com.vlcplayer;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("react.yuanzhou.com.vlcplayer.test", appContext.getPackageName());
25+
}
26+
}

‎android/src/main/AndroidManifest.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
package="com.yuanzhou.vlc">
4+
5+
<application android:label="@string/app_name"
6+
android:supportsRtl="true">
7+
8+
</application>
9+
10+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.yuanzhou.vlc;
2+
3+
4+
import com.facebook.react.ReactPackage;
5+
import com.facebook.react.bridge.JavaScriptModule;
6+
import com.facebook.react.bridge.NativeModule;
7+
import com.facebook.react.bridge.ReactApplicationContext;
8+
import com.facebook.react.uimanager.ViewManager;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
import com.yuanzhou.vlc.vlcplayer.ReactVlcPlayerViewManager;
14+
15+
public class ReactVlcPlayerPackage implements ReactPackage {
16+
17+
@Override
18+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
19+
return Collections.emptyList();
20+
}
21+
22+
// Deprecated RN 0.47
23+
public List<Class<? extends JavaScriptModule>> createJSModules() {
24+
return Collections.emptyList();
25+
}
26+
27+
@Override
28+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
29+
return Collections.<ViewManager>singletonList(new ReactVlcPlayerViewManager());
30+
}
31+
}

0 commit comments

Comments
 (0)
Please sign in to comment.