//
|
// VoiceHandleView.swift
|
// DolphinEnglishLearnStudent
|
//
|
// Created by 无故事王国 on 2024/6/11.
|
//
|
|
import UIKit
|
|
class VoiceHandleView: UIView {
|
|
private lazy var img_hint:UIImageView = {
|
let img = UIImageView(image: UIImage(named: "icon_play_1"))
|
return img
|
}()
|
|
private lazy var img_hint_playing:UIImageView = {
|
let img = UIImageView(image: UIImage(named: "icon_playing"))
|
img.isHidden = true
|
return img
|
}()
|
|
private lazy var btn_play:UIButton = {
|
let btn = UIButton(type: .custom)
|
btn.setImage(UIImage(named: "icon_play"), for: .normal)
|
return btn
|
}()
|
|
var playUrl:String?
|
var listenType:ListenType?
|
private var playAtClouse:((Int)->Void)?
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
setUI()
|
|
VoicePlayer.share().playEnd {
|
self.resetView()
|
}
|
}
|
|
private func setUI(){
|
backgroundColor = UIColor(hexString: "#41A2EB")
|
jq_cornerRadius = 8
|
addSubview(img_hint)
|
img_hint.snp.makeConstraints { make in
|
make.left.equalTo(25)
|
make.centerY.equalToSuperview()
|
make.width.equalTo(27)
|
make.height.equalTo(27)
|
}
|
|
addSubview(img_hint_playing)
|
img_hint_playing.snp.makeConstraints { make in
|
make.center.equalToSuperview()
|
make.width.equalTo(45)
|
make.height.equalTo(31)
|
}
|
|
addSubview(btn_play)
|
btn_play.isUserInteractionEnabled = false
|
btn_play.snp.makeConstraints { make in
|
make.right.equalTo(-23)
|
make.centerY.equalToSuperview()
|
make.width.equalTo(32)
|
make.height.equalTo(32)
|
}
|
|
let playBtn = UIButton(type: .custom)
|
playBtn.addTarget(self, action: #selector(playingAction), for: .touchUpInside)
|
addSubview(playBtn)
|
playBtn.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
func copyView()->VoiceHandleView{
|
let copyView = VoiceHandleView()
|
copyView.listenType = self.listenType
|
copyView.playUrl = self.playUrl
|
copyView.frame = self.frame
|
return copyView
|
}
|
|
func resetView(){
|
img_hint.isHidden = false
|
btn_play.isHidden = false
|
img_hint_playing.isHidden = true
|
}
|
|
func playing(){
|
img_hint.isHidden = true
|
btn_play.isHidden = true
|
img_hint_playing.isHidden = false
|
}
|
|
func playAt(_ clouse:@escaping(Int)->Void){
|
self.playAtClouse = clouse
|
}
|
|
@objc func playingAction(){
|
if let url = playUrl{
|
playAtClouse?(self.tag)
|
VoicePlayer.share().playerAt(url: url)
|
playing()
|
}
|
}
|
|
}
|