안녕하세요.
var Player : AVPlayer?
1. Duration 전체 재생 시간 구하기.
단 예외적으로 플레이 파일 로딩시 Fail이 발생 될수 있어 duration 시간이 없을수도 있으므로
.isNaN 이라는 Exception 처리를 하여 안정성 높이는 코드가 필요.
if let duration = self.Player?.currentItem?.asset.duration{
let seconds = CMTimeGetSeconds(duration)
if !seconds.isNaN {
sendDic.setValue(String(seconds), forKey: "param3")
debugPrint("Duration Seconds : ",String(seconds))
}
}
2. currentTime() 현재 재생 시간 구하기.
단 예외적으로 플레이 파일 로딩시 Fail이 발생 될수 있어 duration 시간이 없을수도 있으므로
.isNaN 이라는 Exception 처리를 하여 안정성 높이는 코드가 필요.
if let duration = self.Player?.currentItem?.currentTime(){
let seconds = CMTimeGetSeconds(duration)
if !seconds.isNaN {
sendDic.setValue(String(seconds), forKey: "param3")
debugPrint("CurrentTime Seconds : ",String(seconds))
}
}
추가 적으로
1. 반올림(round) : 소수점이 5보다 크거나 같으면 올리고 5보다 작으면 내리고
ex: 5.3 -> 5.0, 5.6 -> 6.0
if let duration = self.Player?.currentItem?.currentTime(){
let seconds = CMTimeGetSeconds(duration){
debugPrint("round value : ",round(seconds))
}
}
2. 올림(ceil) : 소수점이 0보다 크면 무조건 올리고
ex: 5.3 -> 6.0, 5.6 -> 6.0
if let duration = self.Player?.currentItem?.currentTime(){
let seconds = CMTimeGetSeconds(duration){
debugPrint("round value : ",ceil(seconds))
}
}
3. 내림(floor) : 소수점 무조건 내리고
ex: 5.3 -> 5.0, 5.6 -> 5.0
if let duration = self.Player?.currentItem?.currentTime(){
let seconds = CMTimeGetSeconds(duration){
debugPrint("round value : ",floor(seconds))
}
}
4. 버림(trunc) : 소수점 그냥 버리고
ex: 5.3 -> 5.0, 5.6 -> 5.0
if let duration = self.Player?.currentItem?.currentTime(){
let seconds = CMTimeGetSeconds(duration){
debugPrint("round value : ",trunc(seconds))
}
}
'iOS, Swift 개발' 카테고리의 다른 글
구글 AdMob 과 Ad Manager 차이점, 개발 그리고 수익 결과 (0) | 2024.03.25 |
---|---|
iOS 애플 디벨로퍼 프로그램 맴버쉽(Apple Developer Program Membership) 갱신 (0) | 2024.03.19 |
iOS App Store 유럽 연합(EU) 디지털 서비스법(DSA) 규정 준수 (1) | 2024.03.15 |
UIAlertController 사용의 구분-아이폰, 아이패드 Device구분 항목(Object C) (0) | 2024.03.14 |
Google Play 정책 회원 탈퇴 요청 (0) | 2023.11.14 |