react-native-omplayer
v1.0.87
Published
video player for react-native
Downloads
133
Maintainers
Readme
ios配置
Build Phases
->Link Binary With Libraries
中添加libz.tbd- 将react-native-omplayer/ios下的
png文件
拖到工程中。
参见index.js
使用说明
import { Video, Audio } from 'react-native-omplayer'
// Video参见video.js
// Audio参见audio.js
<Video
cookie={'111111'} //设置cookie 用于视频加密 (后端使用user-agent) 其他格式任意字符串
src="some url" // 设置url
controls // 是否显示自带控件,默认true
fullscreen // 是否全屏,默认false
repeat // 是否重复,默认false
paused // 是否暂停,默认false
muted // 是否静音,默认false
volume // 音量,0.0-1.0
rate // 播放速率,默认1.0,仅ios有效
currentTime // 播放位置
onLoadStart
onLoad
onLoadStalled
onLoadResume
onError
onProgress
onSeek
onEnd
onFullscreenPlayerWillPresent
onFullscreenPlayerDidPresend
onFullscreenPlayerWillDismiss
onFullscreenPlayerDidDismiss
onReadyForDisplay
onPlaybackStalled
onPlaybackResume
onPlaybackRateChange
/>
// 音频
// 构造,传递listener
const audio = new Audio({
onLoadStart: (evt) => { console.log(evt) },
onLoad: (evt) => { console.log(evt) },
onLoadStalled: (evt) => { console.log(evt) },
onLoadResume: (evt) => { console.log(evt) },
onError: (evt) => { console.log(evt) },
onProgress: (evt) => { console.log(evt) },
onSeek: (evt) => { console.log(evt) },
onEnd: (evt) => { console.log(evt) },
onReadyForPlay: (evt) => { console.log(evt) },
onStalled: (evt) => { console.log(evt) },
onResume: (evt) => { console.log(evt) },
onRateChange: (evt) => { console.log(evt) }
onPlayerError: (evt) => { console.log(evt) }
});
// 初始化
audio.init()
.then(() => {
audio.setRepeat(true);
audio.setMuted(false);
audio.setVolume(1.0);
audio.setRate(1.0);
audio.setSrc("some audio url");
})
.then(() => {
audio.play();
audio.pause();
})
.then(() => {
audio.seek(10);
audio.play();
audio.stop();
});
// 注意释放,不使用的Audio对象必须手动释放,否则内存泄漏
audio.uninit();
// android下如需监听返回键退出全屏,在MainActivity添加如下代码
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == event.KEYCODE_BACK && OMVideoViewManager.cancelFullscreen()) {
return true;
}
return super.onKeyDown(keyCode, event);
}