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

stop / pause the video #68

Closed
dukemarquis opened this issue Mar 14, 2020 · 13 comments
Closed

stop / pause the video #68

dukemarquis opened this issue Mar 14, 2020 · 13 comments

Comments

@dukemarquis
Copy link

Hi eneim, can you show me the way to stop the video when user click the playerView.

I tried methods like pause() in manager but not ganna work and i cannot find way like stop() method in exoplayer.

@dukemarquis
Copy link
Author

i just found two methods i think might gonna work, but i am not sure

  1. dispatchStop() from DefaultControlDispatcher.kt
  2. pause() from PlayerViewBridge

these are both methods i found in the inner class. is that possible to handle pause effect through these two methods?

@dukemarquis
Copy link
Author

i just use this method to gain pause effect, pretty tough process looking through all this XD

9e4ebe98e3bb9c65ee56c6b8a62dbf8

but i guess it's not the best practice, may be you could tell if there is a better way to fulfill this?

@eneim
Copy link
Owner

eneim commented Mar 15, 2020

@plutonem-mobile This requirement is addressed, but not perfectly in Kohii, due to various reason.

If you want to try out, please find the information below:

  1. You need a Manager instance other than just Kohii instance:
val kohii = Kohii[context]
val manager = kohii.register(fragment)
        .addBucket(recyclerView)
  1. When you setup the Video, you need to pass a DefaultControlDispatcher to it:
kohii.setUp(videoUri) {
      tag = "myUniqueTag" // you need a unique tag to make it works
      controller = DefaultControlDispatcher(
          manager, 
          playerView,
          kohiiCanStart = false, // set to false -> if user pause it, Kohii will not start it
          kohiiCanPause = true // set to true -> Kohii will pause it automatically
      )
    }
        .bind(playerView)

By changing the value of kohiiCanStart, and kohiiCanPause you can see how it works. Also it will enable the controller UI of the PlayerView. Note that it is not perfectly work in RecyclerView. Please see this commen for more detail. As said, I'm investigating in designing a better manual playback mechanism.

@dukemarquis
Copy link
Author

okay, thanks eneim, i will try in later then.

@dukemarquis
Copy link
Author

the good news it i am not gonna use it on RecyclerView, just in page like this.

image

@dukemarquis
Copy link
Author

I just try your method but i found that it is little bit out of my point. the design i made is when the user click the playerView, then the video will pause directly without the control panel appear. and the user could click again to resume the video.

is there a better way other than the method i send upward to also achieve this kind of design pattern? (pause without showing control panel)

@eneim
Copy link
Owner

eneim commented Mar 16, 2020

For your use case, please try the practice below:

  1. Create a custom Controller
class MyController(
  val manager: Manager,
  val container: ViewGroup
) : OnClickListener, Controller {

  override fun kohiiCanStart() = true

  override fun kohiiCanPause() = true

  override fun onClick(v: View?) {
    val playable = manager.findPlayableForContainer(container)
    if (playable != null) {
      if (playable.isPlaying()) manager.pause(playable)
      else manager.play(playable)
    }
  }
}
  1. Setup the Video with an instance of MyController:
val myController = MyController(manager, playerView)
kohii.setUp(videoUri) {
      tag = "my-unique-tag"
      controller = myController
    }
        .bind(playerView)

Also set the click listener:

playerView.setOnClickListener(myController)

Note that sometime the PlayerView is not clickable, I have no idea but in that case you may need to wrap it by a FrameLayout or something. You need to set the click listener to that View instead.

@dukemarquis
Copy link
Author

perfect, this method has got me what i want.

just wish kohii could be even better XD.

@eneim
Copy link
Owner

eneim commented Mar 17, 2020

@plutonem-mobile Thanks. Your feedback is indeed help to improve it.

@dinesh1301
Copy link

@eneim Man, you are a rockstar!!

@Nishit79
Copy link

I am using the following versions of thi lib:

implementation "im.ene.kohii:kohii-exoplayer:1.1.1.2011003"
implementation "im.ene.kohii:kohii-core:1.1.1.2011003"

I cant able to find method findPlayableForContainer(container) in Manager class .
val playable = manager.findPlayableForContainer(container)

So will you please provide some update snippet of code regarding pause/play video with user interaction.

I am using your lib in JAVA code.

Thanks in advance.

@eneim
Copy link
Owner

eneim commented Sep 14, 2020

@Nishit79 can you create this in a new issue? Your issue was in a closed one so I could not be notified by it. I will take a look at this soon.

@eneim
Copy link
Owner

eneim commented Sep 14, 2020

@Nishit79 to get the playable instance, you need the Playback instance. Please find a snippet below

kohii.setUp(videoUrl)
        .bind(container, playback -> {
          Playable playable = playback.getPlayable();
          // Do something with the playable.
          return Unit.INSTANCE; // Need to return this.
        });

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

4 participants