Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AVPlayer&;背景音频流_Iphone_Ios_Background_Streaming_Avplayer - Fatal编程技术网

Iphone AVPlayer&;背景音频流

Iphone AVPlayer&;背景音频流,iphone,ios,background,streaming,avplayer,Iphone,Ios,Background,Streaming,Avplayer,我不能让AVPLayer在后台工作,它在应用程序启动时可以完美工作,但当我按下home按钮(在设备中)时,声音停止。 有什么问题 这是APPNAME-.plist: <key>UIBackgroundModes</key> <array> <string>audio</string> </array> }是我的错,上面的代码工作正常。我只是在做plist文件的“测试”副本。对不起,是我的错,上面的代码可以正常工作。

我不能让AVPLayer在后台工作,它在应用程序启动时可以完美工作,但当我按下home按钮(在设备中)时,声音停止。 有什么问题

这是APPNAME-.plist:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

}是我的错,上面的代码工作正常。我只是在做plist文件的“测试”副本。对不起,是我的错,上面的代码可以正常工作。我只是在做plist文件的“测试”副本。抱歉

我已验证此代码,它对我来说工作正常。我已经在iPhone4S上测试过了。@Norbert谢谢你的回答。我的错,我只是在做一个plist文件的“测试”副本…有人有最新的Swift解决方案吗?我已经验证了这个代码,它对我来说工作正常。我已经在iPhone4S上测试过了。@Norbert谢谢你的回答。我的错,我只是在做plist文件的“测试”副本……有人有最新的Swift解决方案吗?
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSURL *url = [NSURL URLWithString:@"mp3url"];
// You may find a test stream at <http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8>.
self.playerItem = [AVPlayerItem playerItemWithURL:url];
[_playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
self.player = [AVPlayer playerWithPlayerItem:_playerItem];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

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

if (context == &ItemStatusContext) {
    NSLog(@"context?");
    AVPlayer *thePlayer = (AVPlayer *)object;
    if ([thePlayer status] == AVPlayerStatusFailed) {
        NSLog(@"error");
        // Respond to error: for example, display an alert sheet.
        return;
    }
    if ([thePlayer status] == AVPlayerStatusReadyToPlay) {
        NSLog(@"ready");
        [[AVAudioSession sharedInstance] setDelegate:self];
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                               error:nil];
        [[AVAudioSession sharedInstance] setActive:YES
                                             error:nil];
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        [_player play];
        return;
    }

    if ([thePlayer status] == AVPlayerStatusUnknown) {
        NSLog(@"unknown");
    }
    // Deal with other status change if appropriate.
}
// Deal with other change notifications if appropriate.
[super observeValueForKeyPath:keyPath ofObject:object
                       change:change context:context];
return;