AVPlayer获取了元数据但没有播放

Tho*_*ard 3 objective-c avfoundation audio-streaming avplayer

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

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
Run Code Online (Sandbox Code Playgroud)

我的目标player,并playerItem强大的性能:

ViewController.h

@interface ViewController : UIViewController

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

@end
Run Code Online (Sandbox Code Playgroud)

Key Value Observer工作得很好,这是我的日志:

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
Run Code Online (Sandbox Code Playgroud)

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

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

没有来自AVPlayer的声音

AVAudioPlayer,没有声音

AVAudioPlayer没有播放任何声音

这就是为什么我使用强大的属性,所以我猜我的问题不是ARC相关的

Tho*_*ard 5

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

但我现在有了一个新问题:当手机处于静音模式时,你怎么能在扬声器上播放声音?(像官方音乐应用程序)

编辑:...答案就在那里: 即使在静音模式下也能在iPhone上播放声音