Comments (13)
For your use case, please try the practice below:
- 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)
}
}
}
- 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.
i just found two methods i think might gonna work, but i am not sure
- dispatchStop() from DefaultControlDispatcher.kt
- 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.
i just use this method to gain pause effect, pretty tough process looking through all this XD
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.
@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:
- You need a
Manager
instance other than justKohii
instance:
val kohii = Kohii[context]
val manager = kohii.register(fragment)
.addBucket(recyclerView)
- 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.
okay, thanks eneim, i will try in later then.
from kohii.
the good news it i am not gonna use it on RecyclerView, just in page like this.
from kohii.
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.
perfect, this method has got me what i want.
just wish kohii could be even better XD.
from kohii.
@plutonem-mobile Thanks. Your feedback is indeed help to improve it.
from kohii.
@eneim Man, you are a rockstar!!
from kohii.
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.
@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.
@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)
- Does PlayerEventListener work? HOT 4
- Lacking documentation on how to change volume HOT 10
- 1.3.0.2011008-20210429.080049-18 is not found at Sonatype HOT 6
- Video player blinks in RecyclerView HOT 5
- Migration from jcenter() to mavenCentral() or google() HOT 2
- Playback.StateListener not return any value HOT 4
- How to stop video playback when the app goes to background HOT 2
- Is the library production ready? HOT 1
- Play Video In Nested Recyclerview
- Why does not you play music in the video? I mean in Recyclerview ... HOT 1
- java.lang.NoSuchMethodError: No static method getNetworkType HOT 2
- Project not building in current stable version of android studio bumblebee HOT 1
- Kohii crash when use exoplayer 2.13.3 NoClassDefFoundError TrackSelection HOT 2
- Kohii with fragment replace HOT 2
- Kohii vs Toro and development status HOT 3
- Caching Video
- is Kohii better than Toro ? HOT 2
- Black Screen while move next video in Recycleview HOT 16
- Can't replay and black screen while play video with same tag in Recycleview HOT 1
- How to change SeekForwardIncrementMs and SeekBackIncrementMs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kohii.