خرید بک لینک

Vote count: 0

How can I only play video for visible cells? Stop the video once the cell is not visible ?

I know it was something to do with indexPathsForVisibleRows but having issue figuring how to implement it

Once Cell is visible at a time currently.

.......

import UIKit
import AVKit
import AVFoundation

class videoDevTable: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWaing() {
    super.didReceiveMemoryWaing()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #waing Incomplete implementation, retu the number of sections
    retu 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #waing Incomplete implementation, retu the number of rows
    retu 3
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! VideoTableViewCell

    let videoURL = NSURL(string: "https://scontent.cdninstagram.com/t50.2886-16/12951809_1538642766431783_2068695559_n.mp4")
    let player = AVPlayer(URL: videoURL!)

    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = cell.playerView.bounds

    cell.playerView.layer.addSublayer(playerLayer)
    player.play()

    retu cell
}

asked 58 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 18 فروردين 1395 ساعت: 22:20

صفحه بندی