2012-04-01 21 views
0

我使用mpmovieplayer播放音頻流。我在處理侵擾時遇到問題,例如收到呼叫時。我的球員在viewcontroller中聲明,我相信我需要在applicationdidresignactive中執行一些操作,在我的appdelegate右邊?如果我的appdelegate不知道我的moviePlayer,該怎麼辦?我是新來iPhone的發展,所以我學習,我去享受吧:)如何從ppdelegate中的applicationwillresignactive調用mpmovieplayer?

以下是我在viewcontroller

-(IBAction)play1MButton:(id)sender{ 

    [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(moviePlayerStatus:) 
     name:MPMoviePlayerPlaybackStateDidChangeNotification 
     object:nil]; 

    NSString *url = @"http://22.22.22.22:8000/listen.pls"; 

    [self.activityIndicator startAnimating]; 

    moviePlayer = [[MPMoviePlayerController alloc] 
     initWithContentURL:[NSURL URLWithString:url]]; 

    [moviePlayer prepareToPlay]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(moviePlayerLoadStateChanged:) 
     name:MPMoviePlayerLoadStateDidChangeNotification 
     object:nil]; 
} 

-(void) moviePlayerStatus:(NSNotification*)notification { 

    //MPMoviePlayerController *moviePlayer = notification.object; 
    MPMoviePlaybackState playbackState = moviePlayer.playbackState; 

    if(playbackState == MPMoviePlaybackStateStopped) { 
     NSLog(@"MPMoviePlaybackStateStopped"); 
    } else if(playbackState == MPMoviePlaybackStatePlaying) { 
     NSLog(@"MPMoviePlaybackStatePlaying"); 
    } else if(playbackState == MPMoviePlaybackStatePaused) { 
     NSLog(@"MPMoviePlaybackStatePaused"); 
    } else if(playbackState == MPMoviePlaybackStateInterrupted) { 
     NSLog(@"MPMoviePlaybackStateInterrupted"); 
    } else if(playbackState == MPMoviePlaybackStateSeekingForward) { 
     NSLog(@"MPMoviePlaybackStateSeekingForward"); 
    } else if(playbackState == MPMoviePlaybackStateSeekingBackward) { 
     NSLog(@"MPMoviePlaybackStateSeekingBackward"); 
    } 
} 

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification { 
    if ([moviePlayer loadState] != MPMovieLoadStateUnknown) 
    { 
     [[NSNotificationCenter defaultCenter] removeObserver:self 
         name:MPMoviePlayerLoadStateDidChangeNotification 
          object:moviePlayer]; 

     [moviePlayer play]; 

     [self.activityIndicator stopAnimating]; 
     [moviePlayer setFullscreen:NO animated:NO]; 
    } 

} 

,並正在做appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    // Override point for customization after application launch. 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 


    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 

    NSError *setCategoryError = nil; 
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; 
    if (setCategoryError) { 

    } 

    NSError *activationError = nil; 
    [audioSession setActive:YES error:&activationError]; 
    if (activationError) { 
    } 

我可以發現錯誤,但是如何使用appdelegate中的播放器?

+0

有人嗎?我仍然無法弄清楚! :( – ss30 2012-04-10 09:16:31

回答

1

嘗試導入MPMoviePlayerController所在的類。在AppDelegate.h「import "YourClassNameWithThePlayer.h"」中使用此代碼。 也許這可以幫助。我也是這方面的新人,我希望你考慮一下。

+0

謝謝你,我做了更多關於這個的閱讀,我想我已經制定出我需要做的事情......我仍在探索ios xcode ..... – ss30 2012-09-01 04:26:46

相關問題