0

ビデオを再生するためのコントローラーを1つ提示します。

  [self presentModalViewController:movieController animated:YES];

支払いが終了したらオブザーバーを追加します。

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) 
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    }

    -(void) movieFinishedPlayback:(NSNotification*)notification{
        NSLog(@"........movieFinishedPlayback....... \n ");
        [self dismissModalViewControllerAnimated:YES];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    }

これは私のVideoDetailViewControllerです。

#import "VideoDetailViewController.h"
#import "PSStackedView.h"
#import "YunMaoIpadAppDelegate.h"

#define IpadAppDelegate ((YunMaoIpadAppDelegate *)[[UIApplication sharedApplication] delegate])
#define IphoneAppDelegate ((YunMaoIosAppDelegate *)[[UIApplication sharedApplication] delegate])

@interface VideoDetailViewController ()

@end

@implementation VideoDetailViewController

@synthesize video, moviePlayer, collectionsArray;

-(id)initWithVideo:(Video *)theVideo
{
    self = [super initWithNibName:@"VideoDetailViewController" bundle:nil];
    if (self) {
        self.video = theVideo;
    }
    return self;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [moviePlayer pause];
    //[self.navigationController setNavigationBarHidden:false animated:animated];
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated;
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

    [super viewDidDisappear:animated];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor blackColor];
}

- (void) viewDidAppear:(BOOL)animated
{
    //[moviePlayer play];
    //[DejalBezelActivityView removeViewAnimated:YES];
    [super viewDidAppear:animated];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self performSelector:@selector(displayActivityView) withObject:self.moviePlayer.view afterDelay:0.1];

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:video.link]];
    [moviePlayer prepareToPlay];

    //[moviePlayer setShouldAutoplay:NO];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

    if([moviePlayer respondsToSelector:@selector(useApplicationAudioSession)])
    {
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            NSLog(@"iPhone ios5.x");
            [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 480.0f, 320.0f)];
            //moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
        }
        else{
            NSLog(@"iPad ios5.x");
            [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)];
            moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
            [moviePlayer.view setFrame:[IpadAppDelegate window].bounds];
        }
    }
    else
    {
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));

            NSLog(@"iPhone ios6.x");
            CGSize result = [[UIScreen mainScreen] bounds].size;
            if(result.height == 480)
            {
                [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
            }
            if(result.height == 568)
            {
                //moviePlayer.controlStyle = MPMovieControlStyleDefault;
                [moviePlayer.view setFrame:self.view.bounds];
            }
        }
        else{
            NSLog(@"ipad ios 6.x");
            [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)];
            //[moviePlayer.view setFrame:[IpadAppDelegate window].bounds];
        }
    }

    [self.view addSubview:moviePlayer.view];
    [moviePlayer play];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
        return YES;
    return NO;
}

- (BOOL)shouldAutorotate{
    return NO;
}

/*
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationLandscapeRight;
}
*/

- (IBAction)displayActivityView
{
    [DejalBezelActivityView activityViewForView:self.moviePlayer.view withLabel:@"节目正在下载中,请稍后..."].showNetworkActivityIndicator = NO;
}

- (void)removeActivityView;
{
    [DejalBezelActivityView removeViewAnimated:YES];
    [[self class] cancelPreviousPerformRequestsWithTarget:self];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

2 に答える 2

1

これは私にとってはうまくいきました。

[self dismissViewControllerAnimated:NO completion:^{
    [self.view removeFromSuperview];
}];

それが役に立てば幸い!

于 2012-12-25T14:00:23.713 に答える
0

movieplayerを却下する前に、スーパービューから[moviePlayer stop];削除してくださいmovieplayer.view。その後、却下してみてください。これで問題が解決する可能性があります。

于 2012-12-25T09:26:41.973 に答える