简体   繁体   中英

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];

It's working on Simulator but in the device, it's not. In the console, I have the following error:

CredStore - performQuery - Error copying matching creds. Error=-25300, query={ class = inet; "m_Limit" = "m_LimitAll"; "r_Attributes" = 1; sync = syna; }

Can anyone help me with a clue?

Please add below code in your app delegate. It may help you

- (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];
}

My answer is for you

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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