English 中文(简体)
如何开始相同的时间, 过去在iphone 中停止了时间
原标题:How to start the same timer which is stop in the past in iphone
  • 时间:2012-05-24 12:53:06
  •  标签:
  • iphone

我是新来的 iphone 。 我正在处理音频播放器, 当用音频播放器点击按键时, 我写了这个代码 。

- (IBAction)playButtonClicked:(id)sender {
    bookTitleString=[[selectBook titleLabel]text];
    startChapterString =[[startChapter titleLabel]text];
    NSString *string = [[NSBundle mainBundle]pathForResource:startChapterString ofType:@"mp3" inDirectory:bookTitleString];
    NSLog(@"string is %@",string);
    NSURL *url = [NSURL fileURLWithPath:string isDirectory:YES];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
    AVURLAsset *audioAsset = [AVURLAsset assetWithURL:url];
    CMTime audioDuration = audioAsset.duration;
    audioDurationInSeconds = CMTimeGetSeconds(audioDuration);
    NSLog(@"audioDurationInSeconds is %f",audioDurationInSeconds);

    slider.userInteractionEnabled= YES;
    slider.minimumValue = 0.0;
    slider.maximumValue = audioDurationInSeconds;
    slider.value = 0.0;
    slider.continuous = YES;
    audioPlayer.delegate = self;
    if(audioPlayer == nil){
        NSLog(@"audio player is nil");
    }
    else
    {
        NSLog(@"audio player is not nil");
        NSLog(@"audioplayer.deviceCurrentTime is %f",audioPlayer.deviceCurrentTime);
        [audioPlayer play];
        timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(sliderTintChanged:) userInfo:nil repeats:YES];
    }
}

以上I 中将使用一个计时器作为类变量

after complete the playing of song it goes to AVAudioPlayerDelegate that is audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag

在此显示此音频Player 已完成播放的代码

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    [timer invalidate];
    NSLog(@"song finished playing");
    NSString *startSongNumber = [[startChapter titleLabel]text];
    NSLog(@"startSongNumber is %@",startSongNumber);
    int songNumber = [startSongNumber intValue];
    NSLog(@"songNumber is %d",songNumber);
    songNumber = songNumber+1;
    NSLog(@"songNumber is %d",songNumber);
    NSString *nextSongNumber = [NSString stringWithFormat:@"%d",songNumber];
    NSLog(@"next song number is %@",nextSongNumber);
   NSString *string = [[NSBundle mainBundle]pathForResource:nextSongNumber ofType:@"mp3" inDirectory:bookTitleString];
    NSLog(@"string is in playerdidfinish is %@",string);
    NSURL *url = [NSURL fileURLWithPath:string isDirectory:YES];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
    AVURLAsset *audioAsset = [AVURLAsset assetWithURL:url];
    CMTime audioDuration = audioAsset.duration;
    audioDurationInSeconds = CMTimeGetSeconds(audioDuration);
    NSLog(@"audioDurationInSeconds is %f",audioDurationInSeconds);
    [audioPlayer play];

}

开始的时候, 我将取消计时器, 然后获得下一首歌路径并开始播放, 但我不知道如何启动在以上方法中停止的计时器

如果任何机构知道这个 请帮助我..

问题回答

就像玩按钮点击的方法一样...

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(sliderTintChanged:) userInfo:nil repeats:YES];

timer is generally use for time increment, it is in seconds. in your method

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(sliderTintChanged) userInfo:nil repeats:YES];

每秒后定时器调用方法 。

-(void)sliderTintChanged
{
   //you can use a variable which will keep timer value
   //like this
   count++;
}

count is an integer variable assign int count=0; when timer will be stopped count has the time in seconds and you can use it.

and NSTimer "fire date" keeps the fire detail in which time the method is call. for more detail read fire date.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签