com.google.android.exoplayer2.ui.SimpleExoPlayerView Java Examples
The following examples show how to use
com.google.android.exoplayer2.ui.SimpleExoPlayerView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StoryView.java From zom-android-matrix with Apache License 2.0 | 6 votes |
private void setCurrentPage() { if (currentPageViewHolder != null) { if (currentPageViewHolder.itemView instanceof SimpleExoPlayerView) { Player player = ((SimpleExoPlayerView)currentPageViewHolder.itemView).getPlayer(); if (player != null) { player.setPlayWhenReady(false); } } } currentPage = getCurrentPagePosition(); currentPageViewHolder = (currentPage >= 0) ? getHistoryView().findViewHolderForAdapterPosition(currentPage) : null; if (currentPageViewHolder != null) { if (currentPageViewHolder.itemView instanceof SimpleExoPlayerView) { SimpleExoPlayerView playerView = (SimpleExoPlayerView) currentPageViewHolder.itemView; playerView.getPlayer().setPlayWhenReady(true); } else if (currentPageViewHolder.itemView instanceof PZSImageView) { getHistoryView().removeCallbacks(advanceToNextRunnable); getHistoryView().postDelayed(advanceToNextRunnable, AUTO_ADVANCE_TIMEOUT_IMAGE); } else if (currentPageViewHolder.itemView instanceof PDFView) { getHistoryView().removeCallbacks(advanceToNextRunnable); getHistoryView().postDelayed(advanceToNextRunnable, AUTO_ADVANCE_TIMEOUT_PDF); } } }
Example #2
Source File: StoryView.java From zom-android-matrix with Apache License 2.0 | 6 votes |
@Override public void onViewRecycled(@NonNull MessageViewHolder holder) { if (holder.itemView instanceof PDFView) { final PDFView pdfView = (PDFView)holder.itemView; pdfView.post(new Runnable() { @Override public void run() { pdfView.recycle(); } }); } else if (holder.itemView instanceof SimpleExoPlayerView) { ((SimpleExoPlayerView)holder.itemView).getPlayer().stop(true); ((SimpleExoPlayerView)holder.itemView).getPlayer().release(); ((SimpleExoPlayerView)holder.itemView).setPlayer(null); } super.onViewRecycled(holder); }
Example #3
Source File: PlayerActivity.java From ExoPlayer-Offline with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
Example #4
Source File: StoryView.java From zom-android-matrix with Apache License 2.0 | 5 votes |
@Override public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View mediaView = null; Context context = parent.getContext(); switch (viewType) { case 2: mediaView = LayoutInflater.from(context).inflate(R.layout.story_viewer_file_info, parent, false); break; case 1: SimpleExoPlayerView playerView = (SimpleExoPlayerView) LayoutInflater.from(context).inflate(R.layout.story_viewer_exo_player, parent, false); mediaView = playerView; mediaView.setBackgroundColor(0xff333333); break; case 0: default: PZSImageView imageView = new PZSImageView(context); mediaView = imageView; imageView.setBackgroundColor(0xff333333); break; } RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mediaView.setLayoutParams(lp); MessageViewHolder mvh = new MessageViewHolder(mediaView); mvh.setLayoutInflater(LayoutInflater.from(parent.getContext())); mvh.setOnImageClickedListener(this); return mvh; }
Example #5
Source File: StoryExoPlayerManager.java From zom-android-matrix with Apache License 2.0 | 5 votes |
public static void recordAudio(AudioRecorder audioRecorder, SimpleExoPlayerView view) { view.setVisibility(View.VISIBLE); VisualizerView visualizerView = view.findViewById(R.id.exo_visualizer_view); if (visualizerView != null) { visualizerView.reset(); visualizerView.setVisibility(View.VISIBLE); audioRecorder.setVisualizerView(visualizerView); } }
Example #6
Source File: VideoPlayerActivity.java From android-arch-components-lifecycle with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SimpleExoPlayerView playerView = findViewById(R.id.simple_exoplayer_view); String videoUrl = "http://docs.evostream.com/sample_content/assets/bunny.mp4"; getLifecycle().addObserver(new VideoPlayerComponent(getApplicationContext(), playerView, videoUrl)); }
Example #7
Source File: LiveVideoPlayerActivity.java From LiveVideoBroadcaster with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); userAgent = Util.getUserAgent(this, "ExoPlayerDemo"); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); rtmpDataSourceFactory = new RtmpDataSource.RtmpDataSourceFactory(); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.activity_live_video_player); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); videoNameEditText = (EditText) findViewById(R.id.video_name_edit_text); videoStartControlLayout = findViewById(R.id.video_start_control_layout); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
Example #8
Source File: VideoPlayerActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
@Override public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { super.onPictureInPictureModeChanged(isInPictureInPictureMode); SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); if (isInPictureInPictureMode) { // Hide the controls in picture-in-picture mode. simpleExoPlayerView.hideController(); } else { // Restore the playback UI based on the playback status. simpleExoPlayerView.showController(); } }
Example #9
Source File: ImageActivity.java From cloudinary_android with MIT License | 4 votes |
private void initExoPlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); exoPlayerView = ((SimpleExoPlayerView) findViewById(R.id.exoPlayer)); exoPlayerView.setPlayer(exoPlayer); listener = new ExoPlayer.EventListener() { @Override public void onTracksChanged(TrackGroupArray trackGroupArray, TrackSelectionArray trackSelectionArray) { if (trackGroupArray.length > 0) { progressBar.setVisibility(View.GONE); } } @Override public void onLoadingChanged(boolean b) { progressBar.setVisibility(b ? View.VISIBLE : View.GONE); } @Override public void onPlayerStateChanged(boolean b, int i) { } @Override public void onPlayerError(ExoPlaybackException e) { progressBar.setVisibility(View.GONE); Toast.makeText(ImageActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { } }; }
Example #10
Source File: PlayerContainerView.java From Anecdote with Apache License 2.0 | 4 votes |
@Override protected void onFinishInflate() { super.onFinishInflate(); mPlayerView = (SimpleExoPlayerView) getChildAt(0); }
Example #11
Source File: VideoPlayerActivity.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void initViews() { simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); textureView = (TextureView) simpleExoPlayerView.getVideoSurfaceView(); }
Example #12
Source File: VideoPlayerComponent.java From android-arch-components-lifecycle with Apache License 2.0 | 4 votes |
VideoPlayerComponent(Context context, SimpleExoPlayerView simpleExoPlayerView, String videoUrl) { this.context = context; this.simpleExoPlayerView = simpleExoPlayerView; this.videoUrl = videoUrl; }
Example #13
Source File: VideoPlayerActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 4 votes |
private void initPlayer() { // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this); // Create the player player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl()); // Bind the player to the view. SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); simpleExoPlayerView.setPlayer(player); // Prepare the player with the source. player.prepare(videoSource); player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setPlayWhenReady(true); final ImageButton playPause = findViewById(R.id.play_pause); player.addListener(new SimpleEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { //update PlayPause-Button if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.play_to_pause_avd); } else { playPause.setImageResource(R.drawable.pause_to_play_avd); } Drawable d = playPause.getDrawable(); if (d instanceof Animatable) { ((Animatable) d).start(); } } else { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.ic_pause_white); } else { playPause.setImageResource(R.drawable.ic_play_arrow_white); } } } }); }
Example #14
Source File: MainActivity.java From WhatsAppStatusSaver with Apache License 2.0 | 4 votes |
public void showImagePopup(Point p, final String uri) { Activity context = MainActivity.this; //COMPLETED solving video problem final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.image_popup_layout); dialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.copyFrom(dialog.getWindow().getAttributes()); dialog.getWindow().setAttributes(lp); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setDimAmount(0); // Getting a reference to Close button, and close the popup when clicked. FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button); ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view); final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view); final SimpleExoPlayer player; if (uri.endsWith(".jpg")) { GlideApp.with(context).load(uri).into(statusImage); } else if (uri.endsWith(".mp4")) { statusImage.setVisibility(View.GONE); simpleExoPlayerView.setVisibility(View.VISIBLE); Uri myUri = Uri.parse(uri); // initialize Uri here // 1. Create a default TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // 3. Create the player player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); //Set media controller simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); //Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); //Produces DataSource instances through which media data is loaded. DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util. getUserAgent(this, "exoplayer2example"), bandwidthMeterA); //Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null); player.prepare(videoSource); player.setPlayWhenReady(true); //run file/link when ready to play. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { player.release(); } }); } close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // popup.dismiss(); dialog.cancel(); } }); }
Example #15
Source File: MediaPlayerFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
@Override public void onViewCreated(View v, Bundle savedInstanceState) { //@Override //public void onCreate(Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); // if (savedInstanceState != null) { // shouldAutoPlay = savedInstanceState.getBoolean("shouldAutoPlay"); // } shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } //setContentView(R.layout.player_activity); View rootView = v.findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) v.findViewById(R.id.controls_root); debugTextView = (TextView) v.findViewById(R.id.debug_text_view); retryButton = (Button) v.findViewById(R.id.retry_button); retryButton.setOnClickListener(this); centerInfo = (TextView) v.findViewById(R.id.centerInfo); // localTime = (TextView) v.findViewById(R.id.localTime); // battery = (BatteryLevelView) v.findViewById(R.id.battery); simpleExoPlayerView = (SimpleExoPlayerView) v.findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); final Intent intent = getActivity().getIntent(); if (intent != null) { Uri extras = intent.getData(); if (extras != null) { currentPathTitle = Uri.decode(extras.getPath()); Log.d(TAG, "intent.getData() " + currentPathTitle); } } updateColor(rootView); }
Example #16
Source File: StoryExoPlayerManager.java From zom-android-matrix with Apache License 2.0 | 4 votes |
public static void load(MediaInfo mediaInfo, SimpleExoPlayerView view, boolean play) { VisualizerView visualizerView = view.findViewById(R.id.exo_visualizer_view); visualizerView.reset(); // Had the player been setup? if (view.getPlayer() == null) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(view.getContext(), trackSelector); // Bind to views visualizerView.setExoPlayer(exoPlayer); view.setPlayer(exoPlayer); } if (mediaInfo.isAudio()) { visualizerView.loadAudioFile(mediaInfo.uri); visualizerView.setVisibility(View.VISIBLE); } else { visualizerView.setVisibility(View.GONE); } view.getVideoSurfaceView().setAlpha(mediaInfo.isAudio() ? 0 : 1); DataSpec dataSpec = new DataSpec(mediaInfo.uri); final VideoViewActivity.InputStreamDataSource inputStreamDataSource = new VideoViewActivity.InputStreamDataSource(view.getContext(), dataSpec); try { inputStreamDataSource.open(dataSpec); } catch (IOException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return inputStreamDataSource; } }; MediaSource mediaSource = new ExtractorMediaSource(inputStreamDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); //LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); ((SimpleExoPlayer)view.getPlayer()).prepare(mediaSource); if (play) { view.getPlayer().setPlayWhenReady(true); //run file/link when ready to play. } }
Example #17
Source File: StoryExoPlayerManager.java From zom-android-matrix with Apache License 2.0 | 4 votes |
public static void stop(SimpleExoPlayerView view) { if (view.getPlayer() != null) { view.getPlayer().setPlayWhenReady(false); } }
Example #18
Source File: StoryView.java From zom-android-matrix with Apache License 2.0 | 4 votes |
@Override public void onBindViewHolder(MessageViewHolder viewHolder, Cursor cursor) { int viewType = getItemViewType(cursor.getPosition()); Context context = viewHolder.itemView.getContext(); try { String mime = cursor.getString(mMimeTypeColumn); Uri uri = Uri.parse(cursor.getString(mBodyColumn)); switch (viewType) { case 2: TextView infoView = (TextView)viewHolder.itemView.findViewById(R.id.text); infoView.setText(uri.getLastPathSegment()); viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, PdfViewActivity.class); intent.setDataAndType(uri,mime); context.startActivity(intent); } }); break; case 1: SimpleExoPlayerView playerView = (SimpleExoPlayerView)viewHolder.itemView; MediaInfo mediaInfo = new MediaInfo(uri, mime); StoryExoPlayerManager.load(mediaInfo, playerView, false); playerView.getPlayer().addListener(new Player.EventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == Player.STATE_ENDED) { advanceToNext(); } } }); break; case 0: default: PZSImageView imageView = (PZSImageView)viewHolder.itemView; try { imageView.setMatrixListener(this); if (SecureMediaStore.isVfsUri(uri)) { info.guardianproject.iocipher.File fileMedia = new info.guardianproject.iocipher.File(uri.getPath()); if (fileMedia.exists()) { Glide.with(context) .asBitmap() .apply(imageRequestOptions) .load(new info.guardianproject.iocipher.FileInputStream(fileMedia)) .into(imageView); } else { Glide.with(context) .asBitmap() .apply(imageRequestOptions) .load(R.drawable.broken_image_large) .into(imageView); } } else { Glide.with(context) .asBitmap() .apply(imageRequestOptions) .load(uri) .into(imageView); } } catch (Throwable t) { // may run Out Of Memory Log.w(LOG_TAG, "unable to load thumbnail: " + t); } break; } } catch (Exception e) { e.printStackTrace(); } if (currentPage == -1) { currentPage = 0; getHistoryView().post(new Runnable() { @Override public void run() { setCurrentPage(); } }); } }