| | |
| | | |
| | | class VoiceHandleView: UIView { |
| | | |
| | | private lazy var img_hint:UIImageView = { |
| | | let img = UIImageView(image: UIImage(named: "icon_play_1")?.themeGreen) |
| | | return img |
| | | }() |
| | | private lazy var img_hint:UIImageView = { |
| | | let img = UIImageView(image: UIImage(named: "icon_play_1")) |
| | | return img |
| | | }() |
| | | |
| | | private lazy var img_hint_playing:UIImageView = { |
| | | private lazy var img_hint_playing:UIImageView = { |
| | | let img = UIImageView(image: UIImage(named: "icon_playing")?.themeGreen) |
| | | img.isHidden = true |
| | | return img |
| | | }() |
| | | img.isHidden = true |
| | | return img |
| | | }() |
| | | |
| | | private lazy var btn_play:UIButton = { |
| | | let btn = UIButton(type: .custom) |
| | | btn.setImage(UIImage(named: "icon_play")?.themeGreen, for: .normal) |
| | | return btn |
| | | }() |
| | | private lazy var btn_play:UIButton = { |
| | | let btn = UIButton(type: .custom) |
| | | btn.setImage(UIImage(named: "icon_play"), for: .normal) |
| | | return btn |
| | | }() |
| | | |
| | | let playBtn = UIButton(type: .custom) |
| | | let playBtn = UIButton(type: .custom) |
| | | |
| | | var playUrl:String? |
| | | var listenType:ListenType? |
| | | private var playAtClouse:((Int)->Void)? |
| | | var isPlayed:Bool = false //是否已播放 |
| | | var playUrl:String? |
| | | var listenType:ListenType? |
| | | private var playAtClouse:((Int)->Void)? |
| | | |
| | | override init(frame: CGRect) { |
| | | super.init(frame: frame) |
| | | setUI() |
| | | override init(frame: CGRect) { |
| | | super.init(frame: frame) |
| | | setUI() |
| | | |
| | | VoicePlayer.share().playEnd { |
| | | self.resetView() |
| | | } |
| | | } |
| | | VoicePlayer.share().playEnd { |
| | | self.resetView() |
| | | } |
| | | } |
| | | |
| | | private func setUI(){ |
| | | // backgroundColor = UIColor(hexString: "#41A2EB") |
| | | private func setUI(){ |
| | | // backgroundColor = UIColor(hexString: "#41A2EB") |
| | | backgroundColor = UIColor.white |
| | | jq_cornerRadius = 8 |
| | | addSubview(img_hint_playing) |
| | | addSubview(img_hint) |
| | | addSubview(btn_play) |
| | | jq_cornerRadius = 8 |
| | | addSubview(img_hint_playing) |
| | | addSubview(img_hint) |
| | | addSubview(btn_play) |
| | | |
| | | img_hint_playing.snp.makeConstraints { make in |
| | | make.center.equalToSuperview() |
| | | make.width.equalTo(45) |
| | | make.height.equalTo(31) |
| | | } |
| | | img_hint_playing.snp.makeConstraints { make in |
| | | make.center.equalToSuperview() |
| | | make.width.equalTo(45) |
| | | make.height.equalTo(31) |
| | | } |
| | | |
| | | btn_play.isUserInteractionEnabled = false |
| | | btn_play.snp.makeConstraints { make in |
| | | make.left.equalTo(img_hint_playing.snp.right).offset(0) |
| | | make.centerY.equalToSuperview() |
| | | make.width.equalTo(32) |
| | | make.height.equalTo(32) |
| | | } |
| | | btn_play.isUserInteractionEnabled = false |
| | | btn_play.snp.makeConstraints { make in |
| | | make.left.equalTo(img_hint_playing.snp.right).offset(0) |
| | | make.centerY.equalToSuperview() |
| | | make.width.equalTo(32) |
| | | make.height.equalTo(32) |
| | | } |
| | | |
| | | img_hint.snp.makeConstraints { make in |
| | | make.right.equalTo(img_hint_playing.snp.left).offset(0) |
| | | make.centerY.equalToSuperview() |
| | | make.width.equalTo(27) |
| | | make.height.equalTo(27) |
| | | } |
| | | img_hint.snp.makeConstraints { make in |
| | | make.right.equalTo(img_hint_playing.snp.left).offset(0) |
| | | make.centerY.equalToSuperview() |
| | | make.width.equalTo(27) |
| | | make.height.equalTo(27) |
| | | } |
| | | |
| | | playBtn.addTarget(self, action: #selector(playingAction), for: .touchUpInside) |
| | | addSubview(playBtn) |
| | | playBtn.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview() |
| | | } |
| | | } |
| | | 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") |
| | | } |
| | | 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 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 |
| | | jq_cornerRadius = 8 |
| | | } |
| | | func resetView(){ |
| | | img_hint.isHidden = false |
| | | btn_play.isHidden = false |
| | | img_hint_playing.isHidden = true |
| | | isPlayed = false |
| | | jq_cornerRadius = 8 |
| | | } |
| | | |
| | | func playing(){ |
| | | img_hint.isHidden = true |
| | | btn_play.isHidden = true |
| | | img_hint_playing.isHidden = false |
| | | } |
| | | func playing(){ |
| | | img_hint.isHidden = true |
| | | btn_play.isHidden = true |
| | | isPlayed = true |
| | | img_hint_playing.isHidden = false |
| | | } |
| | | |
| | | func playAt(_ clouse:@escaping(Int)->Void){ |
| | | self.playAtClouse = clouse |
| | | } |
| | | 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() |
| | | } |
| | | } |
| | | @objc func playingAction(){ |
| | | if let url = playUrl{ |
| | | playAtClouse?(self.tag) |
| | | VoicePlayer.share().playerAt(url: url) |
| | | playing() |
| | | } |
| | | } |
| | | |
| | | } |