Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use ToroExoplayer inside view pager which is inside a container? #496

Open
Aastha-dev opened this issue Jul 16, 2020 · 1 comment

Comments

@Aastha-dev
Copy link

In first case I have already used this player inside container and it is working fine. But on second case there is a container i.e: Recyclerview inside that there is a Viewpager and inside this I have to use this player. So can anyone guide me how can I achieve this. Below code is the View holder of the adapter set inside view pager. Here I am not able to play the player as nothing seems to display.

private val exoVideo = itemView.findViewById(R.id.exoVideo) as PlayerView
private val ivPost = itemView.findViewById(R.id.ivPost) as ImageView
private val ivThumbnail = itemView.findViewById(R.id.ivThumbnail) as ImageView
private val ivVolume = itemView.findViewById(R.id.ivSound) as ImageView
private val ivPlay = itemView.findViewById(R.id.ivPause) as ImageView
private val progressBar = itemView.findViewById(R.id.clpVideoProgressBar) as ProgressBar

private var helper: ExoPlayerViewHelper? = null
private var videoUri: Uri? = null

var listener: EventListener? = null
private val audioManager = itemView.context.getSystemService(AUDIO_SERVICE) as AudioManager

override fun bindFeed(objFeedFile: FeedFile?) {
    if (objFeedFile != null) {
        if (objFeedFile.fileType == Constant.IMAGE) {
            ivPost.visibility = View.VISIBLE
            ivThumbnail.visibility = View.GONE

            Glide.with(itemView.context)
                .load(objFeedFile.fileName)
                .into(ivPost)
        } else {
            this.videoUri = Uri.parse(objFeedFile.fileName)
            ivPost.visibility = View.GONE
            Glide.with(itemView.context)
                .load(objFeedFile.videoThumb)
                .into(ivThumbnail)
        }
    }
}

override fun getPlayerView() = exoVideo

override fun getCurrentPlaybackInfo() = helper?.latestPlaybackInfo ?: PlaybackInfo()

override fun initialize(
    container: Container,
    playbackInfo: PlaybackInfo
) {
    if (helper == null && videoUri != null) {
        Log.i("videoUri",videoUri.toString())
        helper = ExoPlayerViewHelper(this, videoUri!!)
    }

    if (listener == null) {
        listener = object : EventListener {
            override fun onFirstFrameRendered() {
                progressBar.visibility = View.VISIBLE
                ivPlay.visibility = View.GONE
                ivVolume.visibility = View.GONE
                ivThumbnail.visibility = View.VISIBLE
            }

            override fun onBuffering() {
                progressBar.visibility = View.VISIBLE
                ivPlay.visibility = View.GONE
                ivVolume.visibility = View.GONE
                ivThumbnail.visibility = View.VISIBLE
            }

            override fun onPlaying() {
                progressBar.visibility = View.GONE
                ivPlay.visibility = View.GONE
                ivVolume.visibility = View.GONE
                ivThumbnail.visibility = View.GONE
            }

            override fun onPaused() {
                progressBar.visibility = View.GONE
                ivPlay.visibility = View.VISIBLE
                ivVolume.visibility = View.VISIBLE
                ivThumbnail.visibility = View.VISIBLE
            }

            override fun onCompleted() {
                progressBar.visibility = View.GONE
                ivPlay.visibility = View.VISIBLE
                ivVolume.visibility = View.VISIBLE
                ivThumbnail.visibility = View.VISIBLE
            }

        }
        helper!!.addPlayerEventListener(listener!!)
    }
    helper!!.initialize(container, playbackInfo)
}

override fun play() {
    if (helper != null) {
        helper!!.play()
    }
}

override fun pause() {
    helper!!.pause()
}

override fun isPlaying() = helper?.isPlaying ?: false

override fun release() {
    if (listener != null) {
        helper?.removePlayerEventListener(listener)
        listener = null
    }
    helper?.release()
    helper = null
}

override fun wantsToPlay() = visibleAreaOffset(this, itemView.parent) >= 0.65

override fun getPlayerOrder() = adapterPosition
}
@talha01sayed
Copy link

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants