Allow timed metadata to compile on older SDKs
This commit is contained in:
parent
aa89683785
commit
70d863e3d0
@ -37,7 +37,6 @@ public class ReactVideoView extends ScalableVideoView implements
|
|||||||
MediaPlayer.OnPreparedListener,
|
MediaPlayer.OnPreparedListener,
|
||||||
MediaPlayer.OnErrorListener,
|
MediaPlayer.OnErrorListener,
|
||||||
MediaPlayer.OnBufferingUpdateListener,
|
MediaPlayer.OnBufferingUpdateListener,
|
||||||
MediaPlayer.OnTimedMetaDataAvailableListener,
|
|
||||||
MediaPlayer.OnCompletionListener,
|
MediaPlayer.OnCompletionListener,
|
||||||
MediaPlayer.OnInfoListener,
|
MediaPlayer.OnInfoListener,
|
||||||
LifecycleEventListener,
|
LifecycleEventListener,
|
||||||
@ -197,8 +196,10 @@ public class ReactVideoView extends ScalableVideoView implements
|
|||||||
mMediaPlayer.setOnPreparedListener(this);
|
mMediaPlayer.setOnPreparedListener(this);
|
||||||
mMediaPlayer.setOnBufferingUpdateListener(this);
|
mMediaPlayer.setOnBufferingUpdateListener(this);
|
||||||
mMediaPlayer.setOnCompletionListener(this);
|
mMediaPlayer.setOnCompletionListener(this);
|
||||||
mMediaPlayer.setOnTimedMetaDataAvailableListener(this);
|
|
||||||
mMediaPlayer.setOnInfoListener(this);
|
mMediaPlayer.setOnInfoListener(this);
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
|
mMediaPlayer.setOnTimedMetaDataAvailableListener(new TimedMetaDataAvailableListener());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,29 +552,34 @@ public class ReactVideoView extends ScalableVideoView implements
|
|||||||
isCompleted = true;
|
isCompleted = true;
|
||||||
mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null);
|
mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is not fully tested and does not work for all forms of timed metadata
|
||||||
|
@TargetApi(23) // 6.0
|
||||||
|
public class TimedMetaDataAvailableListener
|
||||||
|
implements MediaPlayer.OnTimedMetaDataAvailableListener
|
||||||
|
{
|
||||||
|
public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) {
|
||||||
|
WritableMap event = Arguments.createMap();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) {
|
String rawMeta = new String(data.getMetaData(), "UTF-8");
|
||||||
WritableMap event = Arguments.createMap();
|
WritableMap id3 = Arguments.createMap();
|
||||||
|
|
||||||
try {
|
id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1));
|
||||||
String rawMeta = new String(data.getMetaData(), "UTF-8");
|
id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN");
|
||||||
WritableMap id3 = Arguments.createMap();
|
|
||||||
|
|
||||||
id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1));
|
WritableArray metadata = new WritableNativeArray();
|
||||||
id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN");
|
|
||||||
|
|
||||||
WritableArray metadata = new WritableNativeArray();
|
metadata.pushMap(id3);
|
||||||
|
|
||||||
metadata.pushMap(id3);
|
event.putArray(EVENT_PROP_METADATA, metadata);
|
||||||
|
event.putDouble(EVENT_PROP_TARGET, getId());
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
event.putArray(EVENT_PROP_METADATA, metadata);
|
mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event);
|
||||||
event.putDouble(EVENT_PROP_TARGET, getId());
|
|
||||||
} catch(UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user