有没有办法从AVPlayer类获得音频测量级别?
我知道AVAudioPlayer会这样做,但它不像AVPlayer那样播放流式http .m3u8网址.
我正在使用MonoTouch中的AV Foundation开发AVPlayer API的视频播放器(但是Objective-c中的解决方案也可能很好).我正在尝试实现全屏模式.
为了显示视频帧,我有一个UIView(让我们称之为回放视图),我将AVPlayerLayer添加为回放视图层的子视图:
UIView *playbackView = ...
AVPlayerLayer *playerLayer = ...
[playbackView.layer addSublayer:playerLayer];
Run Code Online (Sandbox Code Playgroud)
图层属性设置如下:
playerLayer.needsDisplayOnBoundsChange = YES;
playbackView.layer.needsDisplayOnBoundsChange = YES;
Run Code Online (Sandbox Code Playgroud)
确保在更改播放视图大小时调整它们的大小.最初,回放视图具有坐标(0,0,320,180)(仅显示在UI的顶部).然后,我通过将回放视图框架大小设置为窗口大小来执行全屏动画:
playbackView.frame = playbackView.window.bounds;
Run Code Online (Sandbox Code Playgroud)
它工作正常.播放视图现在正在填充所有窗口(设置背景颜色以查看它).但我的AVPlayerLayer仍然保持在视图的顶部,就像之前在非全屏模式下一样.
为什么AVPlayer图层不会根据播放视图的新大小调整大小?我是否还需要在AVPlayerLayer上制作动画?使用setNeedsLayout,layoutSubviews刷新(它似乎没有改变某些东西......)?删除AVPlayerLayer并重新添加?
我正在切换MPMoviePlayerController到AVPlayer我需要对视频交换进行更细粒度的控制..mov我正在播放的文件MPMoviePlayerController播放得很好,但在切换到AVPlayer我听到视频中的音频后,视频只显示我添加AVPlayerLayer到的视图背景.这是我如何初始化AVPlayer.
self.player = [[AVPlayer alloc] initWithURL:video];
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
playerLayer.frame = self.playerContainer.bounds;
[self.playerContainer.layer addSublayer:playerLayer];
Run Code Online (Sandbox Code Playgroud)
后来我发了一个.
[self.player play];
Run Code Online (Sandbox Code Playgroud)
播放视频时,我会听到音频,但看不到视频.我也尝试将zPosition设置为没有运气.
playerLayer.zPosition = 1;
Run Code Online (Sandbox Code Playgroud) 我能够成功创建一个播放器,但对最初的黑屏感到恼火.我决定覆盖UIImageView并在播放器启动后隐藏它.这很有用,但我不想为我的所有视频创建和维护图像的麻烦.
我能够通过播放获得我想要的确切结果,并在实例化之后立即暂停播放器.唯一的问题是,有时玩家的状态记录不正确,所以当我再次启动玩家时,状态被列为已经"正在播放",即使播放器已暂停.
我开始研究使用AVPlayerItem seekToTime但没有找到任何可行的解决方案.是否有"非hacky"方式实现这一目标?
我正在使用这种方法来保存AVPlayer的缓冲区数据以用于视频文件.找到这个问题的答案保存AVPlayer的缓冲区数据.
iPhone和iPad - iOS 8.1.3
我做了必要的更改来播放视频,它工作得非常好,除非我尝试播放一段很长的视频(长11-12分钟,大小约为85mb),视频将在连接完成加载后大约4分钟停止.我收到了playbackBufferEmpty事件和播放器项目停止通知.
这是代码的要点
viewController.m
@property (nonatomic, strong) NSMutableData *videoData;
@property (nonatomic, strong) NSURLConnection *connection;
@property (nonatomic, strong) AVURLAsset *vidAsset;
@property (nonatomic, strong) AVPlayerItem *playerItem;
@property (nonatomic, strong) AVPlayerLayer *avlayer;
@property (nonatomic, strong) NSHTTPURLResponse *response;
@property (nonatomic, strong) NSMutableArray *pendingRequests;
/**
Startup a Video
*/
- (void)startVideo
{
self.vidAsset = [AVURLAsset URLAssetWithURL:[self videoURLWithCustomScheme:@"streaming"] options:nil];
[self.vidAsset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
self.pendingRequests = [NSMutableArray array];
// Init Player Item
self.playerItem = [AVPlayerItem playerItemWithAsset:self.vidAsset];
[self.playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我正在捕获10秒的视频并通过FTP上传到服务器,而其他用户可以通过Web服务响应中的URL观看此视频.
根据我的问题,我希望以小尺寸捕获质量好的视频,以便通过FTP上传视频.现在我正在使用.mp4 video formate上传视频,如果有人知道最好的视频形成,可以提高上传速度,然后指导我.
其次,我将所有上传的视频作为URL在Web服务的响应中获取.作为回应,有许多URL,所以我需要在队列中逐个播放视频,最终用户可以向左滑动以在NEXT视频上移动并向右滑动到之前的视频.你可以在这里看到我的代码.
每件事情都很好,但问题需要花费很多时间来上传和播放 (缓冲时间)视频.
请指导我这一点.
评论:在20 MB到1.6 MB的压缩视频中获得成功,因此上传速度位增加,现在正在处理
AVQueuePlayer队列中的播放视频,但有时会将视频卡在播放中.
在swift中处理一个项目,我正在尝试启动AVPlayer,由于某种原因,我告诉我一个例外说法
AudioHardware.cpp:1200:AudioObjectRemovePropertyListener:AudioObjectRemovePropertyListener:没有给定ID为0的对象.
我想问题出在我的网址上.这是我的代码
func initPlayer() {
let url:NSURL = NSURL(string:"https://purelight1-163000.appspot.com/api/user/v2/media/track/60/sample")!
self.playerItem = AVPlayerItem(url: url as URL)
self.player=AVPlayer(playerItem: self.playerItem!)
let playerLayer=AVPlayerLayer(player: self.player!)
playerLayer.frame = CGRect(x: 0, y: 0, width: 10, height: 50) // actually this player layer is not visible
self.view.layer.addSublayer(playerLayer)
}
Run Code Online (Sandbox Code Playgroud) 我试图插入指明了AVPlayerItem的AVURLAsset AVPlayerItemStatusReadyToPlay成AVMutableComposition这样:
composition_ = [[AVMutableComposition alloc] init];
insertionPoint_ = kCMTimeZero;
item_ = [[AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]] retain];
[item_ addObserver:self forKeyPath:@"status" options:0 context:nil];
player_ = [[AVPlayer playerWithPlayerItem:item_] retain];
[player_ addObserver:self forKeyPath:@"currentItem.duration" options:0 context:nil];
/**
* append a player-item to our composition
*/
- (void)addItemToComposition:(AVPlayerItem *)item
{
NSError *error = nil;
VTRACE(@"item duration: %g", CMTimeGetSeconds(item.duration));
if (![composition_ insertTimeRange:CMTimeRangeMake(kCMTimeZero, item.duration)
ofAsset:item.asset
atTime:insertionPoint_
error:&error])
{
VTRACE(@"error: %@", error);
}
}
/**
* simplified value observer callback
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary …Run Code Online (Sandbox Code Playgroud) 我正在使用AVPlayer播放来自URL的音频
在ViewDidLoad中:
self.playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:imageText]];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
[player play];
Run Code Online (Sandbox Code Playgroud)
观察
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:@"status"]) {
if (player.status == AVPlayerStatusReadyToPlay) {
//[playingLbl setText:@"Playing Audio"];
NSLog(@"fineee");
[playBtn setEnabled:YES];
} else if (player.status == AVPlayerStatusFailed) {
// something went wrong. player.error should contain some information
NSLog(@"not fineee");
NSLog(@"%@",player.error);
}
else if (player.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但播放器有时会卡住并且不播放音频,但状态也是AVPlayerStatusReadyToPlay.它永远不会进入AVPlayerStatusFailed或AVPlayerItemStatusUnknown.由于我想处理AVPlayer的错误,它也必须进入这些错误.请帮忙!!
这似乎只是iPhone 6S Plus上的设备特定错误.
脚步:
AVPlayerDemoPlaybackView.xib,使其MPlayback View周围有边距1px灰色线条将出现在顶部和侧面.
任何人都知道如何解决这个问题?
我试图把一个不透明的视图遮住顶部,但这条线仍然会出现在不透明的视图之上!
avplayer ×10
ios ×9
objective-c ×5
avfoundation ×3
iphone ×3
avplayeritem ×1
ftp ×1
swift ×1
swift4 ×1
xamarin.ios ×1
xcode ×1