Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:23:11+00:00 2026-05-30T17:23:11+00:00

I m struggling with this issue for so long but not able to find

  • 0

I m struggling with this issue for so long but not able to find any solution for this

The issue i have is when i pause the audioplayer i want views to be paused from updating so i used timer invalidate to pause the views from loading but when i resume play only Audioplayer is resumed not the views cause i invalidated the timer.

Now i how i can resume updating views from that point where view was paused. By starting the timer again i can start updating views again but how program will know that at what view it was paused and it should resume updating views from that point. There are multiple views involved displayed code for only two.

 -(void)playpauseAction:(id)sender 
{
  if  

  ([audioPlayer isPlaying]){

 [sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateSelected];

 [audioPlayer pause];

 [timer invalidate];

  } else {

 [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];

 [audioPlayer play];

 self.timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:@selector(displayviewsAction:) userInfo:nil repeats:NO];
  }  

}

- (void)displayviewsAction:(id)sender

FirstViewController *viewController = [[FirstViewController alloc] init];

viewController.view.frame = CGRectMake(0, 0, 320, 480);

[self.view addSubview:viewController.view];

[self.view addSubview:toolbar];

[viewController release];

self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(secondViewController) userInfo:nil repeats:NO];

-(void)secondViewController {
SecondViewController *secondController = [[SecondViewController alloc] init];

secondController.view.frame = CGRectMake(0, 0, 320, 480);

[self.view addSubview:secondController.view]; 

[self.view addSubview:toolbar];

[secondController release];

self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(ThirdviewController) userInfo:nil repeats:NO];
}

Thanks and appreciate for your answers and helping me out with this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:23:12+00:00Added an answer on May 30, 2026 at 5:23 pm

    Use a background thread to basically bind the view to the player, something like this:

    UIImageView* imageView;   //the view that gets updated
    
    int current_selected_image_index = 0;
    float time_for_next_image = 0.0;
    
    AVAudioPlayer* audioPlayer;
    
    NSArray* image_times;   //an array of float values representing each 
                            //time when the view should update
    
    NSArray* image_names;   //an array of the image file names 
    
    -(void)update_view
    {
        UIImage* next_image_to_play = [image_names objectAtIndex:current_selected_image_index];
        imageView.image = next_image_to_play;
    }
    
    -(void)bind_view_to_audioplayer
    {
        while(audioPlayer.isPlaying)
        {
            float currentPlayingTime = (float)audioPlayer.currentTime;
            if(currentPlayingTime >= time_for_next_image)
            {
                current_selected_image_index++;
                [self performSelectorOnMainThread:@selector(update_view) withObject:nil waitUntilDone:NO];
                time_for_next_image = [image_times objectAtIndex:[current_selected_image_index+1)];
            }
            [NSThread sleep:0.2];
        }
    }
    
    -(void)init_audio
    {
    current_selected_image_index = 0;
    time_for_next_image = [image_times objectAtIndex:1];
     } 
    
    -(void)play_audio
    {
        [audioPlayer play];
        [self performSelectorInBackground:@selector(bind_view_to_audioplayer) withObject:nil];
    }
    
    -(void)pause_audio
    {
        [audioPlayer pause];
        //that's all, the background thread exits because audioPlayer.isPlaying == NO
        //the value of current_selected_image_index stays where it is, so [self play_audio] picks up 
        //where it left off.
    }
    

    also, add self as observer for the audioPlayerDidFinishPlaying:successfully: notification to reset when the audioplayer finishes playing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this issue for a while now. I have OpenCart 1.5.2.1
I'm new with ruby and rails and have been struggling with this issue for
I'm struggling to find a decent walkthrough for this issue, and was hoping that
I'm currently struggling with this Collection was modified; enumeration operation may not execute issue.
I've been struggling with this for a while. Basically, I want to have two
I have been struggling with this issue for one week, and still far away
I've been struggling with this all day long! In the GemFile, I have: group
I have been struggling with this issue for 3 hours. I know I can
I have been struggling with this NHibernate issue for hours. I extensively researched on
So i've been struggling with this issue for a while... I want to verify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.