androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.54k stars 373 forks source link

How to obtain a picture of the current progress from the mp4 being played by exoplayer #1210

Closed shaohuaboy closed 5 months ago

shaohuaboy commented 5 months ago
exoPlayer = new ExoPlayer.Builder(this).build();
playerView.setPlayer(exoPlayer);
MediaItem mediaItem = MediaItem.fromUri("http://xxxx.mp4");
exoPlayer.setMediaItem(mediaItem);
exoPlayer.prepare();

binding.screenBooton.setOnClickListener(v -> {
            ImageOutput imageOutput = new  ImageOutput() {
                @UnstableApi @Override
                public void onImageAvailable(long presentationTimeUs, Bitmap bitmap) {
                    Log.d(TAG, presentationTimeUs+"毫秒");
                }
                @UnstableApi @Override
                public void onDisabled() {
                    Log.d(TAG, "ImageOutput onDisabled");
                }
            };
            exoPlayer.setImageOutput(imageOutput);
        });

i found imageoutput not do nothing . how to click botton to get one image from video

shaohuaboy commented 5 months ago
TextureView txv = (TextureView) playerView.getVideoSurfaceView();
Bitmap bitmap = txv.getBitmap();

Using textureview can achieve screenshots, butplayerView = new playerView() doesn't know how to set surface-type, and it's best to use surfaceview

shaohuaboy commented 5 months ago

534