Tôi đang cố gắng sao chép số này https://jmacmullin.wordpress.com/2010/11/03/adding-meta-data-to-video-in-ios/ nhanh chóng.Nhận siêu dữ liệu theo thời gian trong Swift ios 8 Từ M3U8 Streaming Video
Dưới đây là một đoạn video mã Jake trong hành động ...
Objective C Timed Metadat in HLS stream
Dưới đây là một liên kết bổ sung cho một cái gì đó tương tự ...
http://cloudfields.net/blog/metadata-audiostream-mpmovieplayercontroller/
Khi video của tôi đang chơi siêu dữ liệu theo thời gian nên cập nhật nút để chuyển hướng đến một url youtube cụ thể trong chế độ xem web khi được nhấp. Video của tôi dài khoảng 15 phút và có 6 url siêu dữ liệu theo thời gian.
Tôi không thể tìm thấy bất kỳ mã hoặc tài liệu nào ở bất kỳ nơi nào về cách đạt được điều này trong Swift. Tôi đã quản lý để chuyển đổi mã Objective C của Jake cho cuộc gọi thông báo của mình.
// Register for meta-data notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(metadataUpdate:)
name:MPMoviePlayerTimedMetadataUpdatedNotification
object:nil];
để Swift Mã
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "metadataUpdated",
name: MPMoviePlayerTimedMetadataUpdatedNotification,
object: nil)
Chức năng của Jake
Actor *actor = [[Actor alloc] init];
if ([player timedMetadata]!=nil && [[player timedMetadata] count] > 0) {
for (MPTimedMetadata *metadata in [player timedMetadata]) {
if ([[metadata.allMetadata valueForKey:@"key"] isEqualToString:@"TPE1"]) {
[actor setName:[metadata.allMetadata objectForKey:@"value"]];
}
if ([[metadata.allMetadata valueForKey:@"key"] isEqualToString:@"WXXX"]) {
NSURL *url = [NSURL URLWithString:[metadata.allMetadata objectForKey:@"value"]];
[actor setProfileURL:url];
}
}
}
// display some UI element for the user to interact with
để Swift
func metadataUpdated (notification: NSNotification!) {
if moviePlayer?.timedMetadata != nil && moviePlayer?.timedMetadata.count > 0 {
for MPTimedMetadata in [moviePlayer?.timedMetadata] {
if MPTimedMetadata?.description == ("TPE1") {
let name = ("value")
}
if MPTimedMetadata?.description == ("WXXX") {
var url = NSURL.observeValueForKeyPath("value")
}
}
}
println("Things are kind of working")
}
}
Đối với cuộc sống của tôi dù tôi không thể tìm ra cách để biến các siêu dữ liệu vào bất kỳ mã nào có thể thao tác. Tôi thực sự cần phải tạo một nút chuyển hướng đến URL được mang trong siêu dữ liệu, nhưng không thể chuyển đổi nó thành một Chuỗi. Bất kỳ trợ giúp nào cũng được đánh giá rất cao. Đây là những gì tôi có cho đến nay.
import UIKit
import MediaPlayer
class ViewController: UIViewController {
var moviePlayer: MPMoviePlayerController?
var youtube = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL(string: "http://path/to/video.m3u8")
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
player.view.sizeToFit()
player.scalingMode = MPMovieScalingMode.None
player.movieSourceType = MPMovieSourceType.Streaming
//player.repeatMode = MPMovieRepeatMode.One
player.play()
self.view.addSubview(player.view)
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "metadataUpdated:",
name: MPMoviePlayerTimedMetadataUpdatedNotification,
object: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func metadataUpdated (notification: NSNotification!) {
if moviePlayer?.timedMetadata != nil && moviePlayer?.timedMetadata.count > 0 {
for MPTimedMetadata in [moviePlayer?.timedMetadata] {
if MPTimedMetadata?.description == ("TPE1") {
let name = ("value")
}
if MPTimedMetadata?.description == ("WXXX") {
var url = NSURL.observeValueForKeyPath("value")
}
}
}
println("Things are kind of working")
}
}
Tôi không chắc chắn nếu tôi hiểu vấn đề của bạn, bạn có gặp khó khăn trong phân tích cú pháp URL hoặc chuyển đổi URL thành một chuỗi? – Vig
Tôi đang gặp sự cố khi chuyển đổi thành chuỗi. Cam ơn vi đa hỏi. Làm cho tôi nhớ đăng kết quả của mình. Cảm ơn! –