Skip to content

Commit

Permalink
HERE IT IS, PURIFIED TO FUCK.
Browse files Browse the repository at this point in the history
  • Loading branch information
Beau Ner committed Oct 10, 2019
1 parent 6bf2134 commit c8e02f3
Show file tree
Hide file tree
Showing 36 changed files with 2,204 additions and 16 deletions.
48 changes: 48 additions & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export default class Video extends Component {
}
};

// ZEROLABS
_onLoadUpdate = (event) => {
if (this.props.onLoadUpdate) {
this.props.onLoadUpdate(event.nativeEvent);
}
};

_onLoad = (event) => {
if (this.props.onLoad) {
this.props.onLoad(event.nativeEvent);
Expand Down Expand Up @@ -209,6 +216,14 @@ export default class Video extends Component {
const isNetwork = !!(uri && uri.match(/^https?:/));
const isAsset = !!(uri && uri.match(/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/));

// ZEROLABS - audioSource url
const audioSource = resolveAssetSource(this.props.audioSource) || {};
let audioUri = audioSource.uri || '';
if (audioUri && audioUri.match(/^\//)) {
audioUri = `file://${audioUri}`;
}
// ZEROLABS END

let nativeResizeMode;
if (resizeMode === VideoResizeMode.stretch) {
nativeResizeMode = NativeModules.UIManager.RCTVideo.Constants.ScaleToFill;
Expand All @@ -233,6 +248,22 @@ export default class Video extends Component {
patchVer: source.patchVer || 0,
requestHeaders: source.headers ? this.stringsOnlyObject(source.headers) : {}
},

// ZEROLABS BEGIN
audioSrc: {
uri: audioUri,
isNetwork,
isAsset,
type: audioSource.type || '',
mainVer: audioSource.mainVer || 0,
patchVer: audioSource.patchVer || 0,
requestHeaders: audioSource.headers
? this.stringsOnlyObject(audioSource.headers)
: {},
},
onVideoLoadUpdate: this._onLoadUpdate,
// ZEROLABS END

onVideoLoadStart: this._onLoadStart,
onVideoLoad: this._onLoad,
onVideoError: this._onError,
Expand Down Expand Up @@ -281,6 +312,21 @@ Video.propTypes = {
PropTypes.number,
PropTypes.object
]),

// ZEROLABS BEGIN
audioSrc: PropTypes.object,
sendLoadUpdate: PropTypes.bool,
audioSource: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
PropTypes.number
]),
onVideoLoadUpdate: PropTypes.func,
onLoadUpdate: PropTypes.func,
// ZEROLABS END


fullscreen: PropTypes.bool,
onVideoLoadStart: PropTypes.func,
onVideoLoad: PropTypes.func,
Expand Down Expand Up @@ -388,6 +434,8 @@ Video.propTypes = {
const RCTVideo = requireNativeComponent('RCTVideo', Video, {
nativeOnly: {
src: true,
// ZEROLABS BOOL 1-LINE
audioSrc: true,
seek: true,
fullscreen: true,
},
Expand Down
17 changes: 17 additions & 0 deletions android-exoplayer/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android-exoplayer</name>
<comment>Project android-exoplayer created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions android-exoplayer/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.6.1))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
9 changes: 6 additions & 3 deletions android-exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ android {

dependencies {
compileOnly "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation('com.google.android.exoplayer:exoplayer:2.9.0') {
// ZL: CHANGED TO VERSION 2.9.6
implementation('com.google.android.exoplayer:exoplayer:2.9.6') {
exclude group: 'com.android.support'
}

Expand All @@ -27,9 +28,11 @@ dependencies {
implementation "com.android.support:support-compat:${safeExtGet('supportLibVersion', '+')}"
implementation "com.android.support:support-media-compat:${safeExtGet('supportLibVersion', '+')}"

implementation('com.google.android.exoplayer:extension-okhttp:2.9.0') {
// ZL: CHANGED TO VERSION 2.9.6
implementation('com.google.android.exoplayer:extension-okhttp:2.9.6') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
// ZL: CHANGED TO VERSION 3.14.0
implementation 'com.squareup.okhttp3:okhttp:3.14.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class ReactExoplayerView extends FrameLayout implements
private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;

// ZEROLABS props
private Uri audioSrcUri;
private String audioExtension;

// Props from React
private Uri srcUri;
private String extension;
Expand Down Expand Up @@ -261,7 +265,20 @@ private void initializePlayer() {
MediaSource videoSource = buildMediaSource(srcUri, extension);
MediaSource mediaSource;
if (mediaSourceList.size() == 0) {

// ZEROLABS START
// Our merge-video-and-audio hack
if (audioSrcUri != null) {
// Gotta merge them both
MediaSource audioSource =
buildMediaSource(audioSrcUri, audioExtension);
MediaSource[] mergeCollection = {videoSource, audioSource};
mediaSource = new MergingMediaSource(mergeCollection);
} else {
// default behaviour
// ZEROLABS END
mediaSource = videoSource;
} // ZL
} else {
mediaSourceList.add(0, videoSource);
MediaSource[] textSourceArray = mediaSourceList.toArray(
Expand Down Expand Up @@ -700,6 +717,26 @@ public void onMetadata(Metadata metadata) {

// ReactExoplayerViewManager public api

// ZEROLABS method
public void setAudioSrc(final Uri uri, final String extension,
Map<String, String> headers) {
if (uri != null) {
boolean isOriginalSourceNull = audioSrcUri == null;
boolean isSourceEqual = uri.equals(audioSrcUri);

this.audioSrcUri = uri;
this.audioExtension = extension;
// this.requestHeaders = headers;
// this.mediaDataSourceFactory =
// DataSourceUtil.getDefaultDataSourceFactory(
// this.themedReactContext, BANDWIDTH_METER, this.requestHeaders);

if (!isOriginalSourceNull && !isSourceEqual) {
reloadSource();
}
}
}

public void setSrc(final Uri uri, final String extension, Map<String, String> headers) {
if (uri != null) {
boolean isOriginalSourceNull = srcUri == null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.brentvatne.exoplayer;

import android.util.Log; // ZEROLABS

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
Expand All @@ -21,6 +23,9 @@

public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerView> {

// ZEROLABS
private static final String PROP_AUDIO_SRC = "audioSrc";

private static final String REACT_CLASS = "RCTVideo";

private static final String PROP_SRC = "src";
Expand Down Expand Up @@ -126,6 +131,35 @@ public void setSrc(final ReactExoplayerView videoView, @Nullable ReadableMap src
}
}

// ZEROLABS METHOD
@ReactProp(name = PROP_AUDIO_SRC)
public void setAudioSrc(final ReactExoplayerView videoView,
@Nullable ReadableMap src) {
Context context = videoView.getContext().getApplicationContext();
String uriString =
src.hasKey(PROP_SRC_URI) ? src.getString(PROP_SRC_URI) : null;
String extension =
src.hasKey(PROP_SRC_TYPE) ? src.getString(PROP_SRC_TYPE) : null;
Map<String, String> headers =
src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS))
: null;

if (TextUtils.isEmpty(uriString)) {
return;
}

if (startsWithValidScheme(uriString)) {
Uri srcUri = Uri.parse(uriString);

if (srcUri != null) {
videoView.setAudioSrc(srcUri, extension, headers);
}
} else {
Log.e("ReactExoPlayerViewManager",
"Video audio - from asset not supported, go for it");
}
}

@ReactProp(name = PROP_RESIZE_MODE)
public void setResizeMode(final ReactExoplayerView videoView, final String resizeModeOrdinalString) {
videoView.setResizeModeModifier(convertToIntDef(resizeModeOrdinalString));
Expand Down
17 changes: 17 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android__</name>
<comment>Project android__ created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(5.6.1))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
1 change: 1 addition & 0 deletions dom/RCTVideoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RCTVideoManager extends RCTViewManager {
.addDirectEvent("onVideoError")
.addDirectEvent("onVideoLoad")
.addDirectEvent("onVideoLoadStart")
.addDirectEvent("onVideoLoadUpdate") // ZEROLABS
.addDirectEvent("onVideoProgress");
}

Expand Down
17 changes: 17 additions & 0 deletions examples/basic/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
17 changes: 17 additions & 0 deletions examples/video-caching/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android_</name>
<comment>Project android_ created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
46 changes: 46 additions & 0 deletions ios/AssetChunk/ChunkAssetLoaderDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// ChunkAssetLoaderDelegate.h
// RCTVideo
//
// The delegate, and the defacto boss of the whole process
//

#ifndef ChunkAssetLoaderDelegate_h
#define ChunkAssetLoaderDelegate_h

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@class RCTVideo;
@class DataRequest;
@class SingleChunk;
@class HunkLoad;

typedef enum : NSUInteger {
VIDEO,
AUDIO
} CALGFormat;



@interface ChunkAssetLoaderDelegate : NSObject <AVAssetResourceLoaderDelegate>

@property (nonatomic,strong) NSURL *fileUrl;

@property (nonatomic, strong) NSMutableArray<DataRequest*> *dataRequests;
@property (nonatomic, strong) NSMutableArray<SingleChunk*> *chunks;
@property (nonatomic, strong) NSMutableArray<HunkLoad*> *hunkLoads;
@property (nonatomic, weak) RCTVideo* vidviewlink;

@property (nonatomic) CALGFormat format;
@property (nonatomic) long int totalSize;
@property (nonatomic) long int highestChunkRequestedSoFar;


-(id) initWithUrl:(NSURL *)url format:(CALGFormat)format vidview:(RCTVideo*) vidview;
- (void)chunkFinishedLoading:(SingleChunk*)who fromHunkLoad:(HunkLoad*)hunk;
- (void)startLoadingWantedChunks;

@end

#endif /* ChunkAssetLoaderDelegate_h */
Loading

0 comments on commit c8e02f3

Please sign in to comment.