google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.75k stars 6.03k forks source link

Only first frame and Audio Plays in Android 23 with MPEG-4 - AVC #11352

Closed x3x0z closed 11 months ago

x3x0z commented 1 year ago

Bug

I am developing an Android application to play Live Streams TS. I am using FFMPEG to decode the audio, this works fine on almost all Android versions. But in Android 23, you only hear the Audio and see the first frame of the video at the moment it was called.

Format video: image

Output Logcat: (Red error messages also appear on mpeg2 videos but these videos do play) image

I have added setVideoFrameMetadataListener event and if it is being called correctly as if the frames were updated, but this is not reflected in the PlayerView.

ExoPlayer Creation:


        renderers.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER)
        val trackSelectionFactory: ExoTrackSelection.Factory = AdaptiveTrackSelection.Factory()
        val trackSelector = DefaultTrackSelector(context, trackSelectionFactory)
        exoPlayer = ExoPlayer.Builder(context, renderers).setTrackSelector(trackSelector).setLoadControl(loadControl).build()
        currentContainerPlayer = containerPlayer
        currentTvHoldSec = tvHoldOk3Sec;

        if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {

        }

        exoPlayer!!.setTrackSelectionParameters(
            exoPlayer!!.getTrackSelectionParameters()
                .buildUpon()
                .setMaxVideoSizeSd()
                .setForceLowestBitrate(true)
                .setPreferredAudioLanguage("hu")
                .build()
        )
        playerView.player = exoPlayer
        playerView.setEnabledShutterView(false)
        exoPlayer!!.setVideoFrameMetadataListener(VideoFrameMetadataListener { presentationTimeUs, releaseTimeNs, format, mediaFormat ->
       //     Log.w(TAG, "New Frame: $presentationTimeUs -- || -- ${releaseTimeNs} ---- ")
            PlayerActivity.lastFrameTimeInMillis = System.currentTimeMillis()
            if (!isReady) isReady = true
        })

        //// METHOD ENCHARGED TO PLAY STREAM

        val extractorsFactory = DefaultExtractorsFactory()
            .setTsExtractorFlags(DefaultTsPayloadReaderFactory.FLAG_ALLOW_NON_IDR_KEYFRAMES)
            .setConstantBitrateSeekingAlwaysEnabled(true)
        val defaultFactory = DefaultHttpDataSource.Factory()
        val token = mPreferences.getString(KEY_PREF_TOKEN_STREAM, "noToken")
        defaultFactory.setDefaultRequestProperties(mapOf("Authorization" to "Bearer $token"))
        val dataSource: DataSource.Factory = defaultFactory
    //    val uri = Uri.parse(url.trim())
        var newUrl : String = url
       // val uri = getUriConvertedToLocal(newUrl)
        val uri = Uri.parse(newUrl)
        Log.w(TAG, "**************** NEW URI:::::::::::::: $uri")
        val drmSchemeUuid: UUID = C.WIDEVINE_UUID
        val type: Int = Util.inferContentType(uri)
        var mediaSource: MediaSource? = null
        val mediaItemBuilder: MediaItem.Builder = MediaItem.Builder(
        ).setUri(uri)

        //non drm streams will be played normally - change drm here

        //non drm streams will be played normally - change drm here
        if (true) {
            mediaItemBuilder.setDrmConfiguration(
                MediaItem.DrmConfiguration.Builder(drmSchemeUuid)
                    .setLicenseUri(drmLicenseUrl).build()
            )
        }

        when (type) {
            C.TYPE_DASH -> {
                Log.i(TAG, "onStart: type dash")
                mediaSource = DashMediaSource.Factory(dataSource)
                    .createMediaSource(mediaItemBuilder.build())
            }
            C.TYPE_SS -> Log.i(TAG, "onStart: type ss")
            C.TYPE_HLS -> {
                Log.i(TAG, "onStart: type hls")
                mediaSource = HlsMediaSource.Factory(dataSource)
                    .createMediaSource(mediaItemBuilder.build())
            }
            C.TYPE_OTHER -> {
                Log.i(TAG, "onStart: type other")
                mediaSource =
                    ProgressiveMediaSource.Factory(dataSource, extractorsFactory)
                        .createMediaSource(
                            mediaItemBuilder.build()
                    )
            }
            else -> {}
        }

        mediaSource?.let { source ->
            player.playWhenReady = playWhenReady
            player.setMediaSource(source, false)
            player.prepare()
        }

        val ratio = mPreferences.getInt("ASPECT_RATIO", 3)
        setRatio(playerView, player, ratio)```
tonihei commented 11 months ago

The com.google.android.exoplayer2 project is now deprecated. We are not accepting any new issues in this project. Please file your issue in the androidx.media3 GitHub project instead: https://github.com/androidx/media/issues

Your issue also sounds very device-specific, so when you file the request, please include a bugreport in case it provides any useful information.