Giter Club home page Giter Club logo

Comments (10)

piemonte avatar piemonte commented on May 16, 2024

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.

ingouackaz avatar ingouackaz commented on May 16, 2024

Hi @piemonte , what do you mean by " moving the time back to zero " ?

Which method should i called ?

from player.

piemonte avatar piemonte commented on May 16, 2024

@ingouackaz hi there. in your prepareCellForReuse or similar method, just set the URL again and it should reset the player

from player.

rromanchuk avatar rromanchuk commented on May 16, 2024

@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

  1. Stops playback
  2. Rewinds playback
  3. 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.

ingouackaz avatar ingouackaz commented on May 16, 2024

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.

piemonte avatar piemonte commented on May 16, 2024

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

piemonte avatar piemonte commented on May 16, 2024

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

rromanchuk avatar rromanchuk commented on May 16, 2024

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

ingouackaz avatar ingouackaz commented on May 16, 2024

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 ?

image

Thank you !

from player.

sentiasa avatar sentiasa commented on May 16, 2024

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)

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.