- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在阅读和尝试 Apple 关于加载视频 Assets 的示例代码。
但我注意到 AVURLAsset
上的 loadValuesAsynchronously
函数永远不会失败,即使我在设备上打开飞行模式或在我的 mac 上关闭 wifi。任何人都知道在什么情况下 loadValuesAsynchronously
将无法加载 key ?
这是相对的sample code :
asset.loadValuesAsynchronously(forKeys: PlayerViewController.assetKeysRequiredToPlay) {
/*
The asset invokes its completion handler on an arbitrary queue.
To avoid multiple threads using our internal state at the same time
we'll elect to use the main thread at all times, let's dispatch
our handler to the main queue.
*/
DispatchQueue.main.async() {
/*
This method is called when the `AVAsset` for our URL has
completed the loading of the values of the specified array
of keys.
*/
/*
Test whether the values of each of the keys we need have been
successfully loaded.
*/
for key in PlayerViewController.assetKeysRequiredToPlay {
var error: NSError?
if asset.statusOfValue(forKey: key, error: &error) == .failed {
let stringFormat = NSLocalizedString("error.asset_%@_key_%@_failed.description", comment: "Can't use this AVAsset because one of it's keys failed to load")
let message = String.localizedStringWithFormat(stringFormat, title, key)
self.handleError(with: message, error: error)
return
}
}
// We can't play this asset.
if !asset.isPlayable || asset.hasProtectedContent {
let stringFormat = NSLocalizedString("error.asset_%@_not_playable.description", comment: "Can't use this AVAsset because it isn't playable or has protected content")
let message = String.localizedStringWithFormat(stringFormat, title)
self.handleError(with: message)
return
}
/*
We can play this asset. Create a new AVPlayerItem and make it
our player's current item.
*/
self.loadedAssets[title] = asset
let name = (thumbnailResourceName as NSString).deletingPathExtension
let type = (thumbnailResourceName as NSString).pathExtension
let path = Bundle.main.path(forResource: name, ofType: type)!
let thumbnail = UIImage(contentsOfFile: path)!
self.assetTitlesAndThumbnails[asset.url] = (title, thumbnail)
}
}
最佳答案
终于想通了,回答我自己的问题:我一直在使用 HLS 视频,URL 的格式为 https://www.foo.com/master.m3u8
。 loadValuesAsynchronously
不会执行任何网络操作来确定 URL 是否包含有效的 HLS 文件。这就是“可播放”键始终有效的原因:
static let assetKeysRequiredToPlay = [
"playable",
"hasProtectedContent"
]
但是,如果我还添加了一些播放信息,例如“duration”和“tracks”,那么如果没有任何网络连接,它将失败,因为它需要实际加载信息。更多细节引用这个答案:https://stackoverflow.com/a/31418812/1035008
关于ios - AVURLAsset loadValuesAsynchronously 从不失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46229228/
这很令人沮丧。我正在尝试获取 AVURLasset 的大小,但尽量避免 naturalSize因为 Xcode 告诉我,这在 iOS5 中已被弃用。 但是:什么是替代品? 我找不到任何关于如何在不使用
我将 AVURLAsset 与各种 AV/MP 播放器类一起使用,它似乎忽略了我服务器的缓存 header 。我正在处理逐渐下载的小型视频(不是 HLS)。 有没有办法确保视频被缓存?有没有办法预先缓
我使用 UIVideoEditorController 来修剪视频。编辑后,在委托(delegate)中,我尝试将视频与其他媒体重新混合。但是,[AVURLAsset trackWithMediaTy
我目前正在编写一个应用程序,该应用程序使用 AVMediaPlayer 来播放下载的 mp3 文件的 AVURLAsset 表示形式。 GUI 在很大程度上基于文件的元数据而不是文件名。我在访问预先存
我想使用 AVPlayer 缓冲视频。我播放一个视频,我希望在第二个视频开始时没有延迟。一种想法是将 AVURLAsset 与此代码一起使用: AVURLAsset *asset = [[A
我在使用 AVURLAsset 时遇到问题。 NSString * const kContentURL = @ "http://devimages.apple.com/iphone/samples/b
我正在尝试将视频文件作为 AVURLAsset 加载到我的 iPad 应用程序中,使用异步加载来等待它准备就绪。问题是,当我运行它时,我收到一条完全通用的“失败”错误消息,我不知道该怎么做。如果我将视
我正在尝试为视频文件创建缩略图: - (UIImage*) thumbnailForVideoAtURL: (NSURL*) videoURL { AVURLAsset *asset = [[
我正在播放一个加密的 m3u8 文件,我需要在一定时间后向播放器发送一个新的“mykey”更新值。 let headers = ["Authorization": "mykey"] let avAss
好的。我有一种不祥的预感,这会被蟋蟀温柔的鸣叫声所满足…… 我基于 this和 this . 我实际上想知道这是否是一个功能,而不是一个错误,因为在本地加载电影然后播放可能存在安全问题。我认为情况并非
在 iOS/TVOS 上,是否可以从 URL 加载远程 .vtt 文件并将其用作字幕轨道,同时远程 HLS 视频也从 URL 加载(而不是在 m3u8 播放列表中指定 VTT )? 伪代码: AVAs
在我的 iOS 应用程序 (SDK 5.6) 中,我从一个短视频创建了一个 AVURLAsset,如下所示: AVURLAsset *asset = [AVURLAsset URLAssetWithU
我正在阅读和尝试 Apple 关于加载视频 Assets 的示例代码。 但我注意到 AVURLAsset 上的 loadValuesAsynchronously 函数永远不会失败,即使我在设备上打开飞
几天前,我被要求检查从 Internet 下载视频时播放视频的难度。我知道这是一项容易的任务,因为刚才有人告诉我。所以,我检查了一下,这非常简单。 问题是我想将视频保存到磁盘上,以免强制用户一次又一次
我正在尝试获取音频文件的持续时间以进行修剪,我正在使用以下代码, audioAsset = [AVURLAsset assetWithURL:itemURL]; CMTime assetTime =
我正在尝试从 iPhone 相机捕获的 .mov 文件中获取缩略图。我目前已将电影保存在应用程序的文档部分中。当我调用 [ Assets 持续时间] 时,它返回一个空对象。此外,当我尝试调用 copy
我试图加载一个名为 output.mov(在 iPhone 上创建)的文件作为 AVURLAsset使用以下代码: NSURL *outputURL = [NSURL fileURLWithPath:
我需要知道我通过 AVURLAsset 从网络播放的视频是纵向还是横向。 过去,我通过获取视频轨道的自然大小、应用其首选变换,然后比较宽度和高度来对本地视频执行此操作。示例: if let asset
我使用 [此处][1] 中的代码在使用 UIImagePickerController 拍摄的视频上附加图像。 视频是纵向的,播放正常,但是一旦我使用 AVURLASSet,它就会变成横向而不是纵向,
我编写了一个自定义 NSURLProtocol(称为“内存:”),它允许我根据名称从 NSDictionary 中获取存储的 NSData 项目。例如,这段代码注册了 NSURLProtocol 类并
我是一名优秀的程序员,十分优秀!