检查iPhone中的网络可达性后,应用程序崩溃了吗? [英] app crashes after checking network reachability in iphone?
本文介绍了检查iPhone中的网络可达性后,应用程序崩溃了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个mpmovieplayercontroller可以在后台播放在线音乐和avaudiosession以便在后台播放相同的音乐,当首次启动没有网络访问的应用程序时,通常我显示没有互联网连接",当我尝试连接到互联网并播放后显示错误
i have a mpmovieplayercontroller to play online music and avaudiosession to play the same music at background, when the first time app launches without network access, normally i shows "no internet connection" , when i tried after connecting to internet and playing it shows the error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'
我的代码在这里
static MPMoviePlayerController *player=nil;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
[MainViewController stopStreaming];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://159.253.145.180:7104"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr];
[[AVAudioSession sharedInstance] setActive: YES error: &activationErr];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
Reachability* reachabile = [Reachability reachabilityWithHostName:@"www.apple.com"];
NetworkStatus remoteHostStatus = [reachabile currentReachabilityStatus];
if(remoteHostStatus == NotReachable)
{
NSLog(@"not reachable");
UIAlertView *notReachableAlert=[[UIAlertView alloc]initWithTitle:@"NO INTERNET CONNECTION" message:@"This Application Need Internet To Run" delegate:self cancelButtonTitle:@"Okay Buddy" otherButtonTitles: nil];
notReachableAlert.delegate=self;
[notReachableAlert show];
[notReachableAlert release];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:player];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(22, 320, 200, 15)] autorelease];
volumeView.center = CGPointMake(152,372);
[volumeView sizeToFit];
[self.view addSubview:volumeView]; // Do any additional setup after loading the view from its nib.
}
当我连接到互联网后单击播放按钮时,应用程序崩溃了吗?
app crashes when i click play button after connecting to internet, any solution?
推荐答案
我认为这是由于静态播放器引起的.尝试使用movieplayer的属性
I think this is due to static player. Try using a property of movieplayer
使用:
@property (nonatomic,retain) MPMoviePlayerController *player;
在实施中:
@synthesize player = _player;
初始化:
MPMoviePlayerController *plyr = [MPMoviePlayerController alloc] init];
self.player = plyr;
[plyr relaease];
在您的代码中
[controller setContentURL:movieURL];
这篇关于检查iPhone中的网络可达性后,应用程序崩溃了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文