-
Notifications
You must be signed in to change notification settings - Fork 95
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
Showing
86 changed files
with
6,725 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
EZPlayer.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,95 @@ | ||
// | ||
// AVAsset+EZPlayer.swift | ||
// EZPlayer | ||
// | ||
// Created by yangjun zhu on 2016/12/28. | ||
// Copyright © 2016年 yangjun zhu. All rights reserved. | ||
// | ||
|
||
import AVFoundation | ||
public extension AVAsset { | ||
|
||
public var title: String? { | ||
var error: NSError? | ||
let status = self.statusOfValue(forKey: "commonMetadata", error: &error) | ||
if error != nil { | ||
return nil | ||
} | ||
if status == .loaded{ | ||
let metadataItems = AVMetadataItem.metadataItems(from: self.commonMetadata, withKey: AVMetadataCommonKeyTitle, keySpace: AVMetadataKeySpaceCommon) | ||
if metadataItems.count > 0 { | ||
let titleItem = metadataItems.first | ||
return titleItem?.value as? String | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
public var closedCaption: [AVMediaSelectionOption]? { | ||
var closedCaptions = [AVMediaSelectionOption]() | ||
if let mediaSelectionGroup = self.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
for option in mediaSelectionGroup.options { | ||
if option.mediaType == "clcp" { | ||
closedCaptions.append(option) | ||
} | ||
} | ||
} | ||
if closedCaptions.count > 0{ | ||
return closedCaptions | ||
} | ||
return nil | ||
} | ||
|
||
public var subtitles: [(subtitle: AVMediaSelectionOption,localDisplayName: String)]? { | ||
var subtitles = [(subtitle: AVMediaSelectionOption,localDisplayName: String)]() | ||
if let mediaSelectionGroup = self.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
for option in mediaSelectionGroup.options { | ||
if !option.hasMediaCharacteristic(AVMediaCharacteristicContainsOnlyForcedSubtitles) { | ||
if let localDisplayName = self.localDisplayName(forMediaSelectionOption: option){ | ||
subtitles.append((option,localDisplayName)) | ||
} | ||
} | ||
} | ||
} | ||
if subtitles.count > 0{ | ||
return subtitles | ||
} | ||
return nil | ||
} | ||
|
||
public var audios: [(audio: AVMediaSelectionOption,localDisplayName: String)]? { | ||
var audios = [(audio: AVMediaSelectionOption,localDisplayName: String)]() | ||
if let mediaSelectionGroup = self.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicAudible){ | ||
for option in mediaSelectionGroup.options { | ||
if let localDisplayName = self.localDisplayName(forMediaSelectionOption: option){ | ||
audios.append((option,localDisplayName)) | ||
} | ||
} | ||
if audios.count > 0{ | ||
return audios | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
public func localDisplayName(forMediaSelectionOption subtitle: AVMediaSelectionOption) -> String?{ | ||
var title: String? = nil | ||
var metadataItems = AVMetadataItem.metadataItems(from: subtitle.commonMetadata, withKey: AVMetadataCommonKeyTitle, keySpace: AVMetadataKeySpaceCommon) | ||
if metadataItems.count > 0 { | ||
let preferredLanguages = NSLocale.preferredLanguages | ||
for language: String in preferredLanguages { | ||
let locale = Locale(identifier: language) | ||
var titlesForLocale = AVMetadataItem.metadataItems(from: metadataItems, with: locale) | ||
if titlesForLocale.count > 0 { | ||
title = titlesForLocale[0].stringValue | ||
break | ||
} | ||
} | ||
if title == nil { | ||
title = metadataItems[0].stringValue | ||
} | ||
} | ||
return title | ||
} | ||
|
||
} |
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,91 @@ | ||
// | ||
// AVPlayerItem+EZPlayer.swift | ||
// EZPlayer | ||
// | ||
// Created by yangjun zhu on 2016/12/28. | ||
// Copyright © 2016年 yangjun zhu. All rights reserved. | ||
// | ||
|
||
import AVFoundation | ||
public extension AVPlayerItem { | ||
|
||
public var bufferDuration: TimeInterval? { | ||
if let first = self.loadedTimeRanges.first { | ||
let timeRange = first.timeRangeValue | ||
let startSeconds = CMTimeGetSeconds(timeRange.start) | ||
let durationSecound = CMTimeGetSeconds(timeRange.duration) | ||
let result = startSeconds + durationSecound | ||
return result | ||
} | ||
return nil | ||
} | ||
|
||
public var selectedMediaCharacteristicLegibleOption:AVMediaSelectionOption?{ | ||
get{ | ||
if let legibleGroup = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
return self.selectedMediaOption(in: legibleGroup) | ||
} | ||
return nil | ||
} | ||
set{ | ||
if let legibleGroup = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
self.select(newValue, in: legibleGroup) | ||
} | ||
} | ||
} | ||
|
||
public var selectedClosedCaptionOption:AVMediaSelectionOption?{ | ||
get{ | ||
if let option = self.selectedMediaCharacteristicLegibleOption{ | ||
if option.mediaType == "clcp" { | ||
return option | ||
} | ||
} | ||
return nil | ||
} | ||
set{ | ||
if let legibleGroup = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
if newValue == nil{ | ||
self.select(newValue, in: legibleGroup) | ||
}else if newValue!.mediaType == "clcp"{ | ||
self.select(newValue, in: legibleGroup) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public var selectedSubtitleOption:AVMediaSelectionOption?{ | ||
get{ | ||
if let option = self.selectedMediaCharacteristicLegibleOption{ | ||
if !option.hasMediaCharacteristic(AVMediaCharacteristicContainsOnlyForcedSubtitles) { | ||
return option | ||
} | ||
} | ||
return nil | ||
} | ||
set{ | ||
if let legibleGroup = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicLegible){ | ||
if newValue == nil{ | ||
self.select(newValue, in: legibleGroup) | ||
}else if !newValue!.hasMediaCharacteristic(AVMediaCharacteristicContainsOnlyForcedSubtitles) { | ||
self.select(newValue, in: legibleGroup) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public var selectedMediaCharacteristicAudibleOption:AVMediaSelectionOption?{ | ||
get{ | ||
if let group = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicAudible){ | ||
return self.selectedMediaOption(in: group) | ||
} | ||
return nil | ||
} | ||
set{ | ||
if let group = self.asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristicAudible){ | ||
self.select(newValue, in: group) | ||
} | ||
} | ||
} | ||
|
||
} |
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,50 @@ | ||
// | ||
// Delay.swift | ||
// EZPlayer | ||
// | ||
// Created by yangjun zhu on 2016/12/28. | ||
// Copyright © 2016年 yangjun zhu. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public typealias Task = (_ cancel : Bool) -> Void | ||
|
||
public func delay(_ time: TimeInterval, task: @escaping ()->()) -> Task? { | ||
|
||
func dispatch_later(block: @escaping ()->()) { | ||
let t = DispatchTime.now() + time | ||
DispatchQueue.main.asyncAfter(deadline: t, execute: block) | ||
} | ||
|
||
|
||
|
||
var closure: (()->Void)? = task | ||
var result: Task? | ||
|
||
let delayedClosure: Task = { | ||
cancel in | ||
if let internalClosure = closure { | ||
if (cancel == false) { | ||
DispatchQueue.main.async(execute: internalClosure) | ||
} | ||
} | ||
closure = nil | ||
result = nil | ||
} | ||
|
||
result = delayedClosure | ||
|
||
dispatch_later { | ||
if let delayedClosure = result { | ||
delayedClosure(false) | ||
} | ||
} | ||
|
||
return result | ||
|
||
} | ||
|
||
public func cancel(_ task: Task?) { | ||
task?(true) | ||
} |
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,19 @@ | ||
// | ||
// EZPlayer.h | ||
// EZPlayer | ||
// | ||
// Created by yangjun zhu on 2016/12/28. | ||
// Copyright © 2016年 yangjun zhu. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//! Project version number for EZPlayer. | ||
FOUNDATION_EXPORT double EZPlayerVersionNumber; | ||
|
||
//! Project version string for EZPlayer. | ||
FOUNDATION_EXPORT const unsigned char EZPlayerVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <EZPlayer/PublicHeader.h> | ||
|
||
|
Oops, something went wrong.