【问题标题】:How can I access iPod Library in my iPhone app如何在我的 iPhone 应用程序中访问 iPod 库
【发布时间】:2011-01-24 13:13:48
【问题描述】:

如何在我的 iPhone 应用程序中访问 iPod 库,比如用户在播放时聆听音乐...比如在 gameloft 游戏中,或从 Photos.app 中的幻灯片放映?

【问题讨论】:

    标签: iphone xcode ipod


    【解决方案1】:

    看看 MPMusicPlayerController。我读过它可以访问 iPod 库。没用过,不知道能不能帮到你……

    【讨论】:

      【解决方案2】:
      - (void)addMusicBtnAction{
          MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
          mediaPicker.delegate = self;
          //mediaPicker.prompt = @"Select Audio";
          mediaPicker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");    
          for (UIWindow* window in [UIApplication sharedApplication].windows) {
              NSArray* subviews = window.subviews;
              if ([subviews count] > 0)
                  for (UIAlertView *alrt in subviews) {
                      if ([alrt isKindOfClass:[UIAlertView class]]){
                          if (alrt.tag == 10020) {
                              [alrt dismissWithClickedButtonIndex:0 animated:YES];
                          }
                      }
                  }
          }    
          [self presentModalViewController:mediaPicker animated:YES];
          //[mediaPicker release];
      }
      - (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
      {
          NSArray * SelectedSong = [mediaItemCollection items];
          if([SelectedSong count]>0){
              MPMediaItem * SongItem = [SelectedSong objectAtIndex:0];
              NSURL *SongURL = [SongItem valueForProperty: MPMediaItemPropertyAssetURL];
      
              NSString *str = [NSString stringWithFormat:@"%@",SongURL];
              appDelegate.musicFilePath = str;
                      //NSLog(@"Audio Loaded");
              UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your audio has been selected"  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil];
              alert.tag = 78787878;
              [alert show];
             // [alert release];
          }
      
          [self dismissModalViewControllerAnimated: YES];   
      }
      // Responds to the user tapping done having chosen no music.
      - (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
      
          [self dismissModalViewControllerAnimated: YES];
      
          [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
      }
      

      【讨论】:

        猜你喜欢
        • 2010-10-11
        • 1970-01-01
        • 2012-01-25
        • 2010-10-12
        • 2010-10-10
        • 1970-01-01
        • 2011-11-26
        • 1970-01-01
        • 2016-09-20
        相关资源
        最近更新 更多