AVPlayer得到了元数据但没有播放 [英] AVPlayer got the metadata but not playing

查看:144
本文介绍了AVPlayer得到了元数据但没有播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个非常简单的应用程序,目的是监听音频流( AAC 64 kbps ).为此,我正在使用Apple AVFoundation中的AVPlayer:

I'm trying to do a very simple application, the purpose is listening an audio stream (AAC 64 kbps). To do so I'm using AVPlayer from the Apple AVFoundation has follow :

ViewController.m

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController
@synthesize playerItem, player;

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://stream.myjungly.fr/MYJUNGLY2"]];
    [playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];

    player = [AVPlayer playerWithPlayerItem:playerItem];
    [player play];

    NSLog(@"player item error : %@", playerItem.error.description);
    NSLog(@"player error : %@", player.error.description);
}

- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
                     change:(NSDictionary*)change context:(void*)context {

    if ([keyPath isEqualToString:@"timedMetadata"])
    {
        AVPlayerItem* _playerItem = object;
        for (AVMetadataItem* metadata in _playerItem.timedMetadata)
        {
            NSLog(@"\nkey: %@\nkeySpace: %@\ncommonKey: %@\nvalue: %@", [metadata.key description], metadata.keySpace, metadata.commonKey, metadata.stringValue);
        }
    }
}

@end

我的对象playerplayerItem strong 属性:

ViewController.h

@interface ViewController : UIViewController

@property (nonatomic, strong) AVPlayerItem* playerItem;
@property (nonatomic, strong) AVPlayer* player;

@end

键值观察器运行良好,这是我的日志:

The Key Value Observer is working great, here is my log :

2013-05-14 11:18:03.725 MusicAvPlayer[6494:907] player item error : (null)
2013-05-14 11:18:03.728 MusicAvPlayer[6494:907] player error : (null)
2013-05-14 11:18:08.140 MusicAvPlayer[6494:907] 
key: title
keySpace: comn
commonKey: title
value: Alabama Shakes - Be Mine

但是,音频没有播放,我没有声音!知道为什么吗?

But the audio is not played, I've go no sound ! Any idea why ?

编辑:我已经看过这个问题了:

I already look at this questions :

AVPlayer没有声音

​​ AVAudioPlayer,无声音

​​ AVAudioPlayer无法播放任何声音

这就是为什么我使用坚固的属性,所以我想我的问题与ARC不相关

That's why I'm using a strong property, so I guess my problem is not ARC related

推荐答案

我发现了问题:iphone处于静音模式...因此扬声器上没有声音,当我使用耳机.

I found problem : the iphone was in silent mode ... so no sound can go out on the speaker, the the sound was played when I was using the head phone.

但是我现在有一个新问题:电话处于静音模式时,如何在扬声器上播放声音? (例如官方的音乐应用程序)

But I've got a new question now : how can you play sound on the speaker when the phone is in silent mode ? (like the official Music application)

...,答案在那里: 即使在静音模式下也可以在iPhone上播放声音

EDIT : ... and the answer is there : Play sound on iPhone even in silent mode

这篇关于AVPlayer得到了元数据但没有播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆