Giter VIP home page Giter VIP logo

Comments (13)

eneim avatar eneim commented on August 24, 2024 1

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.

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

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?

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

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?

from kohii.

eneim avatar eneim commented on August 24, 2024

@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.

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

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

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

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

image

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

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)

from kohii.

dukemarquis avatar dukemarquis commented on August 24, 2024

perfect, this method has got me what i want.

just wish kohii could be even better XD.

from kohii.

eneim avatar eneim commented on August 24, 2024

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

from kohii.

dinesh1301 avatar dinesh1301 commented on August 24, 2024

@eneim Man, you are a rockstar!!

from kohii.

Nishit79 avatar Nishit79 commented on August 24, 2024

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.

from kohii.

eneim avatar eneim commented on August 24, 2024

@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.

from kohii.

eneim avatar eneim commented on August 24, 2024

@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.
        });

from kohii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.