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 8394301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:01:26+00:00 2026-06-09T20:01:26+00:00

I’m working on application for video streaming. It is built with ARC for iOS5.

  • 0

I’m working on application for video streaming. It is built with ARC for iOS5.
To display view I use MPMoviePlayerViewController this way:

.h

@interface EpisodesTableViewController : UITableViewController<EpisodeUrlResolverDelegate> {
    NSTimeInterval playbackTime;
    EpisodeUrlResolver *episodeUrlResolver;
}
@property (strong, nonatomic) MPMoviePlayerViewController *player;
@end

.m

@implementation EpisodesTableViewController
@synthesize episodes, player;

- (void)viewDidLoad
{
    [super viewDidLoad];
    episodeUrlResolver = [[Soap4MeEpisodeUrlResolver alloc] init];
    [episodeUrlResolver setDelegate:self];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:@"WillEnterForeground" object:nil];                 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterBackground) name:@"WillEnterBackground" object:nil];
}

- (void)viewDidUnload
{
    episodeUrlResolver = nil;
    player = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"WillEnterForeground" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"WillEnterBackground" object:nil];
    [super viewDidUnload];
}

- (void)url:(NSURL *)url WasResolvedForEpisode:(Episode *)episode {
    player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    player.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    player.moviePlayer.allowsAirPlay = YES;
    [self presentModalViewController:player animated:YES];
}

- (void)willEnterBackground {
    if (player) {
        playbackTime = player.moviePlayer.currentPlaybackTime;
    }
}

- (void)willEnterForeground {
    if (!player)
        return;
    if(player.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || player.moviePlayer.playbackState == MPMoviePlaybackStateStopped || player.moviePlayer.playbackState == MPMoviePlaybackStatePaused)
    {
        [self continuePlayback];
    }
}

- (void)continuePlayback {
    [self presentModalViewController:player animated:YES];
    [player.moviePlayer setInitialPlaybackTime:playbackTime];
    NSLog(@"%f", player.moviePlayer.initialPlaybackTime);
    [player.moviePlayer play];
}

Few words about presented code:
when url for video is resolved I create the MPMoviePlayerViewController object for video playback. Playback is started. Then when app is going background with home button MPMoviePlayerViewController automatically pauses playback and dissapears from screen (weird behavior, as for me). Thats why I have to save playback time when app is going background and show existing MPMoviePlayerViewController again with restored playback time when app is back to foreground.
It works fine when user presses home button and then is going back to application.

But it doesn’t work when user locks the device. WillEnterBackground notification is fired when
applicationWillEnterForeground is called, so for locking event it is called too.
But in case when user locks the device MPMoviePlayerViewController wasn’t being dismissed properly as in situation when user presses home button. It is hidden from the screen, but calling the code

[self presentModalViewController:player animated:YES];

throws the exception

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <EpisodesTableViewController: 0x91b3950>.'

I tried to change the code to dismiss controller:

- (void)willEnterForeground {
        if (!player)
            return;
        if(player.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || player.moviePlayer.playbackState == MPMoviePlaybackStateStopped || player.moviePlayer.playbackState == MPMoviePlaybackStatePaused)
        {
            if (self.presentedViewController) {
            [self dismissViewControllerAnimated:YES completion:^{
                [self continuePlayback];

            }];
        }
        else {
            [self continuePlayback];
        }
        }
    }

Now it doesn’t throw the exception, but displays warning

wait_fences: failed to receive reply: 10004003

Also completion block is never called.

How to properly to solve the background/foreground continue playing with modally displayed MPMoviePlayerViewController?
Thanks for replies.

  • 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-06-09T20:01:27+00:00Added an answer on June 9, 2026 at 8:01 pm

    I solved the problem.

    Method -willEnterBackground should look like:

    - (void)willEnterBackground {
        if (player) {
            playbackTime = player.moviePlayer.currentPlaybackTime;
            [self dismissModalViewControllerAnimated:NO];
        }
    }
    

    We have to dismiss MPMoviePlayerViewController manually when app is entering background mode.
    Pay attention to use only

    [self dismissModalViewControllerAnimated:NO];
    

    instead of

    [self dismissMoviePlayerViewControllerAnimated];
    

    Thats because MPMoviePlayerViewController was shown with

    [self presentModalViewController:player animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.