Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ protected ReactMediaPlayerView createViewInstance(ThemedReactContext reactContex
@ReactProp(name = "src")
public void setSrc(ReactMediaPlayerView view, @Nullable String uri) {
Log.d(TAG, "setSrc...src=" + uri);
String resourcePrefix = "resource:";
if (uri.startsWith(resourcePrefix)) {
uri = "asset:///" + uri.substring(resourcePrefix.length());
}
view.setUri(uri);
}

Expand Down
12 changes: 11 additions & 1 deletion ios/react-native-media-kit/RCTMediaPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {

- (void)initPlayerIfNeeded {
if(!player) {
player = [AVPlayer playerWithURL:[NSURL URLWithString:self.src]];
NSURL *url;
NSString *resourcePrefix = @"resource:";
if ([self.src hasPrefix:resourcePrefix]) {
NSString *resource = [self.src substringFromIndex:[resourcePrefix length]];
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *file = [mainBundle pathForResource:resource ofType:nil];
url = [NSURL fileURLWithPath:file];
} else {
url = [NSURL URLWithString:self.src];
}
player = [AVPlayer playerWithURL:url];
[self setPlayer:player];
[self addProgressObserver];
[self addObservers];
Expand Down
8 changes: 6 additions & 2 deletions library/MediaPlayerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class MediaPlayerView extends React.Component {
static propTypes = {
...RCTMediaPlayerView.propTypes,
controls: PropTypes.bool,
poster: PropTypes.string
poster: PropTypes.any
}

static defaultProps = {
Expand Down Expand Up @@ -70,6 +70,10 @@ export default class MediaPlayerView extends React.Component {
render() {
let posterView;
if(this.props.poster && this.state.width && this.state.height && this.state.showPoster) {
let posterSource = this.props.poster;
if (typeof(posterSource) === 'string') {
posterSource = {uri: posterSource};
}
posterView = (
<Image
style={{
Expand All @@ -80,7 +84,7 @@ export default class MediaPlayerView extends React.Component {
height: this.state.height,
resizeMode: 'contain'
}}
source={{uri: this.props.poster}}/>
source={posterSource}/>
);
}

Expand Down