Comments (10)
hey @uguryavas thanks for the interest in the library. player can be used in "Vine-like" table view cells.
if you're not already familiar, you just need to think about supporting cell re-use, i recommend reallocating the player controller and resetting the cell back to the original thumbnail.
it's possible for you to try using the same player controller instances and "resetting" them when re-use occurs, as oppose to reallocating the controller, but i can't remember if there were any bugs in doing so. by reset, i just mean that you're moving the time back to zero and providing the asset URL over again. I recommend probably just re-allocating.
i've had friends ask me about some type of stream caching, so that the videos play faster but i haven't had a need to get into that optimization.
from player.
Hi @piemonte , what do you mean by " moving the time back to zero " ?
Which method should i called ?
from player.
@ingouackaz hi there. in your prepareCellForReuse or similar method, just set the URL again and it should reset the player
from player.
@piemonte i'm actually implementing this now, it's working actually quite well without having to instantiate the controller every load. The only problem is it's a little bit tricky properly cleaning up the cell. I think it would be nice either add a convenience method, or allow for a path
to be passed nil which indicates a reset state.
Maybe a convenience method like prepareForReuse()
that
- Stops playback
- Rewinds playback
- Hides the preview layer (like in the init methods)
Right now i'm reaching into the class to do all of these cleanup methods.
But just a note for others trying to do this, prepareForReuse
is just for resetting the cell, but it's up to the implement cells that may be long living. When a cell goes off screen you need to utilize techniques like tableView(_:didEndDisplayingCell:forRowAtIndexPath:)
I also wouldn't recommend setting any data in prepareForReuse
as it's tableView(_:cellForRowAtIndexPath:)
responsibility, you may be working with stale data.
from player.
Hi @rromanchuk !
I've just realised that many people have the same issue as me.
http://stackoverflow.com/questions/17617066/avplayer-plays-on-simulator-but-doesnt-on-a-real-device
It works perfectly on the simulator, but it doesnt on the device.
@piemonte any idea ?
from player.
@rromanchuk awesome ideas. we can put a little extension on there that provides that func. i can probably add it this evening or sometime tomorrow. ✌️
from player.
@ingouackaz not sure what you're encountering, if you can reproduce that problem with the Player
sample project, please create an issue with a gist of the changes that trigger it. thanks for the proj interest.
from player.
@piemonte i can submit a UITable/CollectionView example too. I had to hack a bit of the player to add this 'reset' method because a lot of things are are managed in init/deinit so a bit tricky to keep it DRY
public func sharedSetup() {
self.playerView.playerLayer.hidden = true
self.playerView.playerLayer.addObserver(self, forKeyPath: PlayerReadyForDisplay, options: (NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old), context: &PlayerLayerObserverContext)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive:", name: UIApplicationWillResignActiveNotification, object: UIApplication.sharedApplication())
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationDidEnterBackground:", name: UIApplicationDidEnterBackgroundNotification, object: UIApplication.sharedApplication())
}
private func sharedDeinit() {
NSNotificationCenter.defaultCenter().removeObserver(self)
self.playerView.layer.removeObserver(self, forKeyPath: PlayerReadyForDisplay, context: &PlayerLayerObserverContext)
self.player.pause()
self.setupPlayerItem(nil)
}
public func reset() {
sharedDeinit()
sharedSetup()
}
from player.
I have almost fixed it !
@rromanchuk , @piemonte , do you know , how i can add or remove the bottom layer in AVPLayerViewController wich contains the play controls, the progress bar,and the fullscreen button ?
Thank you !
from player.
Hi @rromanchuk, @ingouackaz and @piemonte. If you made Player work for the TableViews, can you please write a mini-guide on how to achieve that? Should I put the code @rromanchuk shared above in my Player.swift, and then call reset()
on TableViewController's cellForRowAtIndexPath
?
Before, I was using this in my UITableViewCell to call a gif, but I want to adapt Player instead of gif. This is how I get the link of the video:
func getVid() {
if let vidName = self.post?["video"].string {
if let vidURL = NSURL(string: "http://my.app/vid/\(vidName).mp4") {
// do?
}
}
}
(getVid()
function is getting called on click on thumbnail)
I also use Player as a default video player, however I got confused how to exactly adapt it to TableViewCells. How should I exactly apply this approach in the TableViewController and/or TableViewCell? I'd be very happy if you can help. Thanks
from player.
Related Issues (20)
- Suppor for VTT?
- Video Controls HOT 1
- AVPlayer times out on iOS 14 beta HOT 2
- Can add playback speed support HOT 1
- Aspect ratio not working on iOS 14 beta 6 HOT 2
- iOS 14 problem with portrait video HOT 2
- PlayerDelegate playerBufferTimeDidChange, it doesnt return what player
- How to create custom view on video player
- How to add HTTP Headers with the url. HOT 1
- Setting up Player with AVPlayerItem.
- How can Local Video Play HOT 1
- cannot play locally stored mp4 files HOT 1
- Can't pause video when open from the URL. HOT 1
- Not working
- Orientation & play issue
- Video doesn't play on iPhone 6 ios 12.4 HOT 2
- Player may be crash.
- No thing display
- Dont Work
- update to better support SwiftUI
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 player.