Commit 5bc88467 authored by David黄金龙's avatar David黄金龙

视频播放功能

parent 591a900a
......@@ -16,10 +16,6 @@ class YHHomePageViewController: YHBaseViewController {
return viewModel
}()
lazy var items = {
return [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: "")]
}()
lazy var homeCollectView = {
// 设置布局方向
let flowLayout = YHHomeCollectionLayout()
......@@ -32,7 +28,6 @@ class YHHomePageViewController: YHBaseViewController {
collectinoView.register(YHHomeCollectionViewCell.self, forCellWithReuseIdentifier:YHHomeCollectionViewCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
// collectinoView.bounces = false
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
return collectinoView
......
......@@ -8,6 +8,8 @@
import UIKit
import Kingfisher
import AVFoundation
import AVKit
class YHHomeCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHHomeCollectionViewCell"
......@@ -73,6 +75,33 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
setupUI()
}
lazy var playButton: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "home_play_btn"), for: .normal)
// btn.isHidden = true
return btn
}()
lazy var playerViewController: AVPlayerViewController = {
let vc = AVPlayerViewController()
return vc
}()
}
extension YHHomeCollectionViewCell {
@objc func clickPlayButton() {
if let url = URL(string: "https://upload.cdn.galaxy-immi.com/sell/production/video/1638527500518.mp4") {
let player = AVPlayer(url:url)
playerViewController.player = player
self.parentViewController?.present(playerViewController, animated: true) {
self.playerViewController.player!.play() // 开始播放视频
}
}
}
private func setupUI() {
contentView.clipsToBounds = true
contentView.addSubview(titleImageView)
......@@ -115,6 +144,16 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
heartImageViewBtn.addTarget(self, action: #selector(clickHeart), for: .touchUpInside)
heartImageViewBtn.YH_clickEdgeInsets = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
contentView.addSubview(playButton)
playButton.snp.makeConstraints { make in
make.top.equalToSuperview().offset(8)
make.right.equalToSuperview().offset(-8)
make.width.height.equalTo(20)
}
playButton.addTarget(self, action: #selector(clickPlayButton), for: .touchUpInside)
}
func updataSubViews() {
......@@ -139,6 +178,8 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
heartImageViewBtn.isSelected = listModel.is_like
}
@objc func clickHeart() {
guard let listModel = listModel else { return }
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "编组-21@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "编组-21@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment