-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
301a9b7
commit 956fca5
Showing
2 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
HMH_iOS/HMH_iOS/Presentation/Home/Models/HomeViewTotalDataModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |