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

Event when a card is displayed #8

Open
Isuru-Nanayakkara opened this issue Nov 19, 2017 · 2 comments
Open

Event when a card is displayed #8

Isuru-Nanayakkara opened this issue Nov 19, 2017 · 2 comments

Comments

@Isuru-Nanayakkara
Copy link

Hi,

I have to play a bunch of videos retrieved from the internet on cards. This is my view generator.

let viewGenerator: (Video, CGRect) -> (UIView) = { (video: Video, frame: CGRect) -> (UIView) in
      let containerView = UIView(frame: self.view.bounds)
      
      let asset = AVURLAsset(url: URL(string: video.url)!)
      asset.resourceLoader.setDelegate(self, queue: DispatchQueue.main)
      
      let player = AVPlayer(playerItem: AVPlayerItem(asset: asset))
      player.actionAtItemEnd = .none
      
      let playerLayer = AVPlayerLayer(player: player)
      playerLayer.frame = self.view.bounds
      playerLayer.backgroundColor = UIColor.clear.cgColor
      
      containerView.layer.addSublayer(playerLayer)
      
      player.play()
      return containerView
  }

Is there a way to get notified when each card is shown in the screen? A delegate method perhaps.

The reason is, it's a little different than displaying static views or images. Because view/image cards are sort of "preloaded", right? When I add video player cards in the view generator, I have to set it to play player.play() right within the generator. The problem is then all the preloaded videos also get played simultaneously.

If there's a way to get notified when each card is displayed, maybe I could make it play when that happens.

@D-32
Copy link
Owner

D-32 commented Nov 19, 2017

Inside DMSwipeCardsView.swift locate the two methods cardSwipedLeft & cardSwipedRight. In both methods, before calling loadNextCard, you should have the card that now has become on top somewhere in the self.loadedCards array. Probably it's the last element. You could then force cast it to your own class & call your play method.

@i-am-chris
Copy link

maybe we can improve on this, by making a delegate function as currentCard id / value, etc.?

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

3 participants