繁体   English   中英

AVPlayer在模拟器上运行,但不在设备上运行

[英]AVPlayer Works on Simulator, but not on device

  playerItem=[AVPlayerItem playerItemWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.radio.com.lk/y-fm/"]]];
  player=[AVPlayer playerWithPlayerItem:playerItem] ;
  [player play];

它正在使用模拟器,但在设备中,它不是。 在控制台中,我有以下错误:

CredStore - performQuery - 复制匹配的信息时出错。 错误= -25300,query = {class = inet; “m_Limit”=“m_LimitAll”; “r_Attributes”= 1; sync = syna; }

任何人都可以帮我一个线索吗?

请在您的应用代表中添加以下代码。 它可能会帮助你

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}

我的回答是给你的

ViewController.h

#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) AVPlayerViewController *playerViewController;
@property (nonatomic,strong)AVAudioPlayer *player;
- (IBAction)actionPlay:(id)sender;
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController
@synthesize player;
@synthesize playerViewController;

- (void)viewDidLoad {
    [super viewDidLoad];
}
- (IBAction)actionPlay:(id)sender {
    AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:yourURL];
    AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
    playerViewController = [[AVPlayerViewController alloc] init];
    playerViewController.player = playVideo;
    playerViewController.player.volume = 0;
    playerViewController.view.frame = self.view.bounds;
    [self.view addSubview:playerViewController.view];
    [playVideo play];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM