9VAeãã ãã¹ãéçºè¨é²
Â
仿¥ã¯ä»¥ä¸ã®ä½æ¥ã宿½
- æ¥æ¬èªã¡ãã¥ã¼ã®æè¼
- é³ã®åç
æ¥æ¬èªã¡ãã¥ã¼
ãµã³ãã«ããã°ã©ã CoreTextPageViewer ã®ãã¼ã«ãã¼ãæ¹é ãã¦ãã¡ãã¥ã¼ãã¼ãä½æãæ¥æ¬èªã¨è±èªã®åãæ¿ãæ©è½ãæè¼ã
é³ã®åç
以ä¸ãåç §
AudioPlayerã使ã£ã¦ã®é³ãé³´ããã¦ã¿ã - Object for cutie
AVAudioPlayer - AVFoundation | Apple Developer Documentation
iphone - AVAudioPlayer working in Simulator, but not on device - Stack Overflow
é³ã®ãã¡ã¤ã«ã¯ã9VAeã¨åããã©ã«ãã«ããã¨ãã¦ããã¡ã¤ã«ãã¹ããã¡ã¤ã«åãåå¾ã§ããã®ã§ãNSString, NSURL ãçæãåçãããã
Â
ä¸ã«æ¸ãããæ¹æ³ã試ãã¦ã¿ãã¨ãé³ã®ãã¡ã¤ã«ãæºåããã¨ããã§ã¨ã©ã¼ãçºçããåå ãããããªãã£ãããã¡ã¤ã«ãèªã¿ã ããæã«çºçããã¨ã©ã¼ã¡ãã»ã¼ã¸ãåå¾ããã«ã¯ã次ã®ããã« @try @catch ã§å²ãã¨ããããã ãã¨ã©ã¼å 容ãã¢ã©ã¼ãã§åå¾ã§ããã
Â
     case qVAcPMSCinp:   // 鳿¥½åç
    {
      if ([qvaView.musicPlayer isPlaying]){
        [qvaView.musicPlayer stop];
        [qvaView.musicPlayer release];
        qvaView.musicPlayer=nil;
      }
      @try {
        qvaView.musicURL = [qvaView getIoFilePath]; //鳿¥½ãã¡ã¤ã«ãã¹ãåå¾
        qvaView.musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: qvaView.musicURL error:nil];
      }
      @catch (NSException *exception) {
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"Error"
                                message:exception.description
                               delegate:self
                           cancelButtonTitle:@"Ok"
                           otherButtonTitles:nil];
        [alert show];
      }
      qvaView.musicPlayer.delegate = qvaView; //delegateè¨å®
      [qvaView.musicPlayer play]; //鳿¥½åç
Â
Â
ãã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ããã鳿¥½ãã¬ã¼ã¤ã¼ã@property (copy, nonatomic)ãã§ç¢ºä¿ãã¦ããã®ãåå ã¨å¤æï¼copyå¦çä¸ã«ã¨ã©ã¼ï¼ã@property (retain, nonatomic) ã«å¤æ´ããã¨é³ãé³´ãããã«ãªã£ãã
Â
鳿¥½ã®åççµäºãåå¾ããããã«ãdelegateãè¨å®ãã
- delegateï¼ã³ã¼ã«ããã¯é¢æ°ï¼ãããå ´æãæå®ããµã³ãã«ã§ã¯ self ã¨æ¸ããã¦ãããããã§ã¯ãqvaView.musicPlayer.delegate = qvaView;ãã¨è¨è¼
- delegateãããã¯ã©ã¹ã«ã¯ã<AVAudioPlayerDelegate>ãã¤ãã
@interface QvaeView : UIView <AVAudioPlayerDelegate>
Â
- delegate颿°ã以ä¸ã®ããã«è¨è¼ãããã¯ãOSã®ãã¼ã¸ã§ã³ã«ãã£ã¦å¼æ°ã®å®ç¾©ãå¤ãã£ã¦ããããã ãdelegate颿°ã®å®ç¾©ããæ£ãããã®ãè¨è¼ãä¸ã®é¢æ°ãåççµäºéç¥ãä¸ã®é¢æ°ã¯ãã³ã¼ãã¨ã©ã¼éç¥ã
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
  Â
}
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError * __nullable)error{
  Â
}
Â
Â