本文整理汇总了Java中com.google.android.exoplayer2.SimpleExoPlayer类的典型用法代码示例。如果您正苦于以下问题:Java SimpleExoPlayer类的具体用法?Java SimpleExoPlayer怎么用?Java SimpleExoPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleExoPlayer类属于com.google.android.exoplayer2包,在下文中一共展示了SimpleExoPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPlayer
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
/**
* Set the {@link SimpleExoPlayer} to use. The {@link SimpleExoPlayer#setTextOutput} and
* {@link SimpleExoPlayer#setVideoListener} method of the player will be called and previous
* assignments are overridden.
*
* @param player The {@link SimpleExoPlayer} to use.
*/
public void setPlayer(SimpleExoPlayer player) {
if (this.player == player) {
return;
}
if (this.player != null) {
this.player.setTextOutput(null);
this.player.setVideoListener(null);
this.player.removeListener(componentListener);
this.player.setVideoSurface(null);
}
this.player = player;
shutterView.setVisibility(VISIBLE);
if (player != null) {
if (surfaceView instanceof TextureView) {
player.setVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SurfaceView) {
player.setVideoSurfaceView((SurfaceView) surfaceView);
}
player.setVideoListener(componentListener);
player.addListener(componentListener);
player.setTextOutput(componentListener);
}
}
示例2: createFullPlayer
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的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: switchTargetView
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
/**
* Switches the view targeted by a given {@link SimpleExoPlayer}.
*
* @param player The player whose target view is being switched.
* @param oldPlayerView The old view to detach from the player.
* @param newPlayerView The new view to attach to the player.
*/
public static void switchTargetView(@NonNull SimpleExoPlayer player,
@Nullable SimpleExoPlayerView oldPlayerView, @Nullable SimpleExoPlayerView newPlayerView) {
if (oldPlayerView == newPlayerView) {
return;
}
// We attach the new view before detaching the old one because this ordering allows the player
// to swap directly from one surface to another, without transitioning through a state where no
// surface is attached. This is significantly more efficient and achieves a more seamless
// transition when using platform provided video decoders.
if (newPlayerView != null) {
newPlayerView.setPlayer(player);
}
if (oldPlayerView != null) {
oldPlayerView.setPlayer(null);
}
}
示例4: onBind
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的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;
}
示例5: setPlayer
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
public void setPlayer(SimpleExoPlayer player) {
if (this.player == player) {
return;
}
if (this.player != null) {
this.player.removeListener(this);
}
this.player = player;
if (player != null) {
player.addListener(this);
boolean playing = player.getPlayWhenReady();
setIsPlaying(playing);
}
updateAll();
}
示例6: seekOrSkip
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
private void seekOrSkip() {
if (fsmPlayer == null) {
return;
}
if (fsmPlayer instanceof FsmPlayer) {
if (((FsmPlayer) fsmPlayer).getController() != null) {
SimpleExoPlayer adPlayer = ((FsmPlayer) fsmPlayer).getController().getAdPlayer();
if (adPlayer != null && adPlayer.getPlaybackState() == ExoPlayer.STATE_BUFFERING) {
long position = adPlayer.getCurrentPosition() + 1000 < adPlayer.getDuration() ? adPlayer.getCurrentPosition() + 1000 : adPlayer.getDuration();
adPlayer.seekTo(position);
adPlayer.setPlayWhenReady(true);
return;
}
}
}
}
示例7: updateMovieResumePosition
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
/**
* update the resume position of the main movice
*
* @param controller
*/
public static void updateMovieResumePosition(PlayerUIController controller) {
if (controller == null) {
return;
}
SimpleExoPlayer moviePlayer = controller.getContentPlayer();
if (moviePlayer != null && moviePlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) {
int resumeWindow = moviePlayer.getCurrentWindowIndex();
long resumePosition = moviePlayer.isCurrentWindowSeekable() ? Math.max(0, moviePlayer.getCurrentPosition())
: C.TIME_UNSET;
controller.setMovieResumeInfo(resumeWindow, resumePosition);
}
}
示例8: performWorkAndupdatePlayerUI
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
@Override
public void performWorkAndupdatePlayerUI(@Nullable FsmPlayer fsmPlayer, @NonNull PlayerUIController controller, @NonNull PlayerComponentController componentController, @NonNull MediaModel movieMedia, @Nullable AdMediaModel adMedia) {
// doesn't need to do any UI work.
if (isNull(fsmPlayer, controller, componentController, movieMedia, adMedia)) {
return;
}
SimpleExoPlayer moviePlayer = controller.getContentPlayer();
// this mean, user jump out of the activity lifecycle in ReceivedAdState.
if (moviePlayer!=null && moviePlayer.getPlaybackState() == ExoPlayer.STATE_IDLE) {
fsmPlayer.transit(Input.ERROR);
}
}
示例9: prepareExoPlayerForUri
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
public SimpleExoPlayer prepareExoPlayerForUri(
int playerKey,
@NonNull Context context,
@NonNull Uri uri,
@NonNull SimpleExoPlayerView simpleExoPlayerView,
int currentWindow,
boolean playWhenReady,
long playbackPosition) {
SimpleExoPlayer simpleExoPlayer = playersInUse.get(playerKey);
if (simpleExoPlayer == null) {
simpleExoPlayer = setUpMediaPlayer(context);
simpleExoPlayerView.setPlayer(simpleExoPlayer);
simpleExoPlayer.setPlayWhenReady(playWhenReady);
simpleExoPlayer.seekTo(currentWindow, playbackPosition);
MediaSource mediaSource = setUpMediaSource(context, uri);
simpleExoPlayer.prepare(mediaSource, true, false);
playersInUse.put(playerKey, simpleExoPlayer);
} else {
simpleExoPlayer.seekTo(currentWindow, playbackPosition);
simpleExoPlayer.setPlayWhenReady(playWhenReady);
}
return simpleExoPlayer;
}
示例10: PlayerView
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
public PlayerView(Context context, SimpleExoPlayer player) {
super(context);
simpleExoPlayerView = new SimpleExoPlayerView(context);
progressBar = new ProgressBar(context);
textView = new TextView(context);
textView.setX(40);
textView.setY(20);
textView.setTextColor(Color.parseColor("#FFFFFF"));
textView.setTextSize(16);
textView.setText("By Herudi");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
simpleExoPlayerView.setLayoutParams(new SimpleExoPlayerView.LayoutParams(
SimpleExoPlayerView.LayoutParams.MATCH_PARENT,
SimpleExoPlayerView.LayoutParams.MATCH_PARENT
));
setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
));
setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
addView(simpleExoPlayerView);
addView(textView);
addView(progressBar,params);
simpleExoPlayerView.setUseController(true);
simpleExoPlayerView.requestFocus();
simpleExoPlayerView.setPlayer(player);
simpleExoPlayerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() {
@Override
public void onVisibilityChange(int visibility) {
if (visibility==0){
textView.setVisibility(VISIBLE);
}else {
textView.setVisibility(GONE);
}
}
});
}
示例11: onCreate
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Uri uri = intent.getParcelableExtra("uri");
long playerPosition = intent.getLongExtra("position", C.TIME_UNSET);
int playerWindow = intent.getIntExtra("windowIndex", 0);
boolean rotation = intent.getBooleanExtra("rotation", false);
if (rotation) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
playerInstance = ExoPlayerInstance.getInstance();
SimpleExoPlayer player = playerInstance.getPlayer();
setContentView(R.layout.activity_video_player);
playerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
playerView.setPlayer(player);
if (playerPosition == C.TIME_UNSET) {
player.seekToDefaultPosition(playerWindow);
} else {
player.seekTo(playerWindow, playerPosition);
}
playerInstance.prepare(uri, null);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
示例12: create
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的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: prepareMediaForPlaying
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
private void prepareMediaForPlaying() {
reset();
if (mMediaSourceUri != null) {
MediaSource mediaSource = onCreateMediaSource(mMediaSourceUri);
mPlayer.prepare(mediaSource);
} else {
return;
}
mPlayer.setAudioStreamType(mAudioStreamType);
mPlayer.setVideoListener(new SimpleExoPlayer.VideoListener() {
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
float pixelWidthHeightRatio) {
getCallback().onVideoSizeChanged(ExoPlayerAdapter.this, width, height);
}
@Override
public void onRenderedFirstFrame() {
}
});
notifyBufferingStartEnd();
getCallback().onPlayStateChanged(ExoPlayerAdapter.this);
}
示例14: LeanbackPlayerAdapter
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
/**
* Builds an instance. Note that the {@code PlayerAdapter} does not manage the lifecycle of the
* {@link SimpleExoPlayer} instance. The caller remains responsible for releasing the player when
* it's no longer required.
*
* @param context The current context (activity).
* @param player Instance of your exoplayer that needs to be configured.
* @param updatePeriodMs The delay between player control updates, in milliseconds.
*/
public LeanbackPlayerAdapter(Context context, SimpleExoPlayer player, final int updatePeriodMs) {
this.context = context;
this.player = player;
handler = new Handler();
componentListener = new ComponentListener();
controlDispatcher = new DefaultControlDispatcher();
updateProgressRunnable = new Runnable() {
@Override
public void run() {
Callback callback = getCallback();
callback.onCurrentPositionChanged(LeanbackPlayerAdapter.this);
callback.onBufferedPositionChanged(LeanbackPlayerAdapter.this);
handler.postDelayed(this, updatePeriodMs);
}
};
}
示例15: doActionAndScheduleNextImpl
import com.google.android.exoplayer2.SimpleExoPlayer; //导入依赖的package包/类
@Override
protected void doActionAndScheduleNextImpl(final SimpleExoPlayer player,
final MappingTrackSelector trackSelector, final Surface surface, final Handler handler,
final ActionNode nextAction) {
if (nextAction == null) {
return;
}
Player.EventListener listener = new Player.DefaultEventListener() {
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
if (timeline.equals(expectedTimeline)) {
player.removeListener(this);
nextAction.schedule(player, trackSelector, surface, handler);
}
}
};
player.addListener(listener);
if (player.getCurrentTimeline().equals(expectedTimeline)) {
player.removeListener(listener);
nextAction.schedule(player, trackSelector, surface, handler);
}
}