Gần đây tôi đã gặp sự cố tương tự. Các giải pháp cảm thấy một chút hacky nhưng nó làm việc như xa như tôi thấy. Trước tiên, tôi thiết lập một người quan sát cho thông báo Nhật ký Truy cập mới:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAVPlayerAccess:)
name:AVPlayerItemNewAccessLogEntryNotification
object:nil];
Cuộc gọi này hoạt động. Nó có lẽ có thể được tối ưu hóa nhưng đây là ý tưởng cơ bản:
- (void)handleAVPlayerAccess:(NSNotification *)notif {
AVPlayerItemAccessLog *accessLog = [((AVPlayerItem *)notif.object) accessLog];
AVPlayerItemAccessLogEvent *lastEvent = accessLog.events.lastObject;
float lastEventNumber = lastEvent.indicatedBitrate;
if (lastEventNumber != self.lastBitRate) {
//Here is where you can increment a variable to keep track of the number of times you switch your bit rate.
NSLog(@"Switch indicatedBitrate from: %f to: %f", self.lastBitRate, lastEventNumber);
self.lastBitRate = lastEventNumber;
}
}
Mỗi lần có một mục mới vào nhật ký truy cập, nó sẽ kiểm tra tốc độ bit chỉ định cuối cùng từ sự xâm nhập gần đây nhất (các lastObject trong nhật ký truy cập cho mục trình phát). Nó so sánh tốc độ bit được chỉ định này với thuộc tính đã lưu tốc độ bit từ thay đổi cuối cùng đó.
Bí quyết! Cảm ơn bạn: D – tcacciatore