本文整理汇总了Java中com.google.android.exoplayer2.ExoPlayerFactory类的典型用法代码示例。如果您正苦于以下问题:Java ExoPlayerFactory类的具体用法?Java ExoPlayerFactory怎么用?Java ExoPlayerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExoPlayerFactory类属于com.google.android.exoplayer2包,在下文中一共展示了ExoPlayerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
.setOnAudioFocusChangeListener(audioFocusChangeListener)
.setAcceptsDelayedFocusGain(false)
.setWillPauseWhenDucked(true)
.setAudioAttributes(audioAttributes)
.build();
}
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mediaSession = new MediaSessionCompat(this, "PlayerService");
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setCallback(mediaSessionCallback);
Context appContext = getApplicationContext();
Intent activityIntent = new Intent(appContext, MainActivity.class);
mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));
exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
exoPlayer.addListener(exoPlayerListener);
DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
this.extractorsFactory = new DefaultExtractorsFactory();
}
示例2: createFullPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
/***
* 创建实例播放实例,并不开始缓冲
**/
private SimpleExoPlayer createFullPlayer() {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
BufferingLoadControl loadControl = new BufferingLoadControl();
if (null == modelType) {
setDefaultLoadModel();
} else {
loadControl.setListener(new LoadListener() {
@Override
public void onProgress(long pro) {
getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%");
}
});
}
DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl);
player.setPlaybackParameters(playbackParameters);
getPlayerViewListener().setPlayer(player);
return player;
}
示例3: onBind
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
@Override
public IBinder onBind(final Intent intent) {
bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "SyncPlayer"), bandwidthMeter);
extractorsFactory = new DefaultExtractorsFactory();
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
SimpleExoPlayer player =
ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
mMediaPlayer = player;
setCompletionListener();
nbuilder.setSmallIcon(R.mipmap.ic_launcher);
return mBinder;
}
示例4: initPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
protected void initPlayer() {
// 1. Create a default TrackSelector
mMainHandler = new Handler();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
mTrackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
mTrackSelectionHelper = new TrackSelectionHelper(this, mTrackSelector,videoTrackSelectionFactory);
// 3. Create the mTubiExoPlayer
mTubiExoPlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector);
mEventLogger = new EventLogger(mTrackSelector);
mTubiExoPlayer.addListener(mEventLogger);
mTubiExoPlayer.setAudioDebugListener(mEventLogger);
mTubiExoPlayer.setVideoDebugListener(mEventLogger);
mTubiExoPlayer.setMetadataOutput(mEventLogger);
mTubiPlayerView.setPlayer(mTubiExoPlayer, this);
mTubiPlayerView.setMediaModel(mediaModel,true);
mTubiPlayerView.setTrackSelectionHelper(mTrackSelectionHelper);
}
示例5: initializePlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void initializePlayer() {
if (player == null) {
// a factory to create an AdaptiveVideoTrackSelection
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
// using a DefaultTrackSelector with an adaptive video selection factory
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this),
new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl());
player.addListener(componentListener);
player.addVideoDebugListener(componentListener);
player.addAudioDebugListener(componentListener);
playerView.setPlayer(player);
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
}
MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash)));
player.prepare(mediaSource, true, false);
}
示例6: initializePlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void initializePlayer(Uri videoUri){
if (mExoPlayer == null){
TrackSelector trackSelector = new DefaultTrackSelector();
LoadControl loadControl = new DefaultLoadControl();
mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
mExoPlayer.addListener(this);
mExoPlayer.seekTo(currentPosition);
mPlayerView.setPlayer(mExoPlayer);
String userAgent = Util.getUserAgent(getContext(), "Tasty");
MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory(
getContext(), userAgent), new DefaultExtractorsFactory(), null, null);
mExoPlayer.prepare(mediaSource);
if (playWhenReady) mExoPlayer.setPlayWhenReady(true);
else mExoPlayer.setPlayWhenReady(false);
}
}
示例7: startPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
@Override
public void startPlayer() {
if(exoPlayer==null){
exoPlayer =
ExoPlayerFactory.newSimpleInstance(
context, new DefaultTrackSelector(), new DefaultLoadControl());
exoPlayer.addListener(this);
}
exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
context, Util.getUserAgent(context, "uamp"), null);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(
Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null);
exoPlayer.prepare(mediaSource);
configPlayer();
}
示例8: setExoViewSource
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource)
throws IOException
{
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
exoView.setPlayer(exoPlayer);
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}
示例9: setupExoPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void setupExoPlayer() {
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
exoPlayer = ExoPlayerFactory.newSimpleInstance(
new DefaultRenderersFactory(this),
new DefaultTrackSelector(adaptiveTrackSelectionFactory),
new DefaultLoadControl());
pvVideoPreview.setPlayer(exoPlayer);
exoPlayer.setPlayWhenReady(true);
Uri uri = Uri.parse("asset:///sample_video.mp4");
MediaSource mediaSource = createMediaSource(this, uri);
LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource);
exoPlayer.prepare(loopingMediaSource, true, false);
}
示例10: initializePlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void initializePlayer() {
if (player == null) {
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
player.addListener(this);
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, "testApp"), bandwidthMeter);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl),
dataSourceFactory, extractorsFactory, null, null);
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(true);
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
if (haveResumePosition) {
Log.d(TAG, "Have Resume position true!" + resumePosition);
player.seekTo(resumeWindow, resumePosition);
}
player.prepare(videoSource, !haveResumePosition, false);
}
}
示例11: initExoPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void initExoPlayer(MediaSource sampleSource) {
if (exoPlayer == null) {
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// 2. Create the player
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
}
exoPlayer.prepare(sampleSource);
exoPlayer.setVideoSurfaceView(svPlayer);
exoPlayer.setPlayWhenReady(true);
initMediaControls();
}
示例12: create
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
@NonNull
public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator,
DefaultDrmSessionManager.EventListener drmSessionEventListener,
MediaCodecSelector mediaCodecSelector) {
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener);
RenderersFactory renderersFactory = new SimpleRenderersFactory(
context,
drmSessionManager,
EXTENSION_RENDERER_MODE_OFF,
DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS,
mediaCodecSelector
);
DefaultLoadControl loadControl = new DefaultLoadControl();
return ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
}
示例13: KExoMediaPlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
public KExoMediaPlayer(Context context) {
this.context = context.getApplicationContext();
// [email protected]@=========
TrackSelection.Factory trackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, new DefaultLoadControl(),
null);
player.addListener(eventLogger);
player.addListener(playerListener);
player.setVideoListener(playerListener);
player.setPlayWhenReady(false);
mainHandler = new Handler();
userAgent = Util.getUserAgent(this.context, "KExoMediaPlayer");
mediaDataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent, BANDWIDTH_METER);
}
示例14: loadVideo
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
public void loadVideo(){
// CommonTools.showErrorLog("test"+"11111111111");
// CommonTools.showErrorLog("test"+playerPosition);
if (player == null){
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl(), null, false);
player.addListener(this);
setPlayer(player);
// CommonTools.showErrorLog("test"+"222222222");
if (playerPosition > 0){
// CommonTools.showErrorLog("test"+"3333333333");
player.seekTo(playerPosition);
}
player.setPlayWhenReady(isAutoPlay);
}
if (uri == null){
// CommonTools.showToast(getContext(), "请选择一个视频来播放");
return;
}
MediaSource mediaSource = buildMediaSource(uri, null);
player.prepare(mediaSource);
}
示例15: initializePlayer
import com.google.android.exoplayer2.ExoPlayerFactory; //导入依赖的package包/类
private void initializePlayer() {
simpleExoPlayerView.requestFocus();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
simpleExoPlayerView.setPlayer(player);
MediaSource[] mediaSources = new MediaSource[videos.size()];
for (int i = 0; i < videos.size(); i++) {
mediaSources[i] = buildMediaSource(Uri.parse(videos.get(i).videoUrl));
}
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
: new ConcatenatingMediaSource(mediaSources);
player.prepare(mediaSource);
}