Skip to content

Commit

Permalink
[Feat/#81] Handler - 비디오 핸들러 파일 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
boyeon0119 committed Jan 14, 2024
1 parent 301a9b7 commit 956fca5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
56 changes: 49 additions & 7 deletions HMH_iOS/HMH_iOS/Global/Handler/VideoHandler.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
//
// VideoHandler.swift
// HMH_iOS
//
// Created by 김보연 on 1/14/24.
//

import Foundation
import AVFoundation

class VideoHandler: NSObject {
var avPlayer: AVPlayer? = AVPlayer()

override init() {
super.init()
self.addObserver()
}

func bindVideoItem(videoURL: URL) {
DispatchQueue.main.async {
let avPlayerItem = AVPlayerItem(url: videoURL)
self.avPlayer?.replaceCurrentItem(with: avPlayerItem)
self.avPlayer?.play()
}
}

func removeEndTimeObserver() {
NotificationCenter.default.removeObserver(self,
name: .AVPlayerItemDidPlayToEndTime,
object: self.avPlayer?.currentItem)
}

func addObserver() {
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime,
object: self.avPlayer?.currentItem,
queue: nil) { [weak self] (_) in
guard let self else { return }
self.avPlayer?.seek(to: CMTime.zero)
self.avPlayer?.play()
}
}


func playVideo() {
self.avPlayer?.play()
}

func pauseVideo() {
self.avPlayer?.pause()
}

func disposeVideo() {
self.avPlayer?.pause()
self.avPlayer?.replaceCurrentItem(with: nil)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// HomeViewTotalDataModel.swift
// HMH_iOS
//
// Created by 김보연 on 1/14/24.
//

import Foundation

0 comments on commit 956fca5

Please sign in to comment.