2

ビデオを埋め込んだアプリケーションを書いています。最初にアプリケーションをランドスケープモードで起動してからビデオを起動すると、見栄えがします。それで、[完了]をクリックして、ビデオをもう一度再生します。2回目は、ビデオが左下にシフトされます。ビデオをクリックしても、[完了]ボタンが表示されません。シミュレーターをポートレートモードに切り替えてからランドスケープモードに戻す必要があります。その後、[完了]をクリックしてビデオを停止できます。常にビデオをポートレートモードで開始してから、シミュレーターをランドスケープにすると、動作します。私はこれを何度も行うことができ、ビデオは常に適切に整列します。ただし、アプリケーションを常に横向きモードで再生すると、初回以降の再生ごとに、ビデオは常に下および左にシフトします。私は他の多くのmpmovieplayerの質問に目を通し、自分のコードを他のコードと比較しました。私はIOS6とストーリーボードを使用しています。以下に基本的なMPMOVIEPLAYERコードをコピーしました。私は本当にここで立ち往生しています

MoviePlayerViewController.m

- (void) readyPlayer
 mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

// For 3.2 devices and above
if ([mp respondsToSelector:@selector(loadState)]) 
{
    // Set movie player layout
    [mp setControlStyle:MPMovieControlStyleFullscreen];
    [mp setFullscreen:YES];


    // May help to reduce latency
    [mp prepareToPlay];

    // Register that the load state changed (movie is ready)
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayerLoadStateChanged:) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];
}  

// Register to receive a notification when the movie has finished playing. 
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:nil];
// Register to receive a notification when the movie has exit fullscreen mode.
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerDidExitFullscreenNotification
                                           object:nil];
}

/*---------------------------------------------------------------------------
 * For 3.2 and 4.x devices
 *  
*--------------------------------------------------------------------------*/
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification 
{
// Unless state is unknown, start playback
if ([mp loadState] != MPMovieLoadStateUnknown)
{
    // Remove observer
    [[NSNotificationCenter defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerLoadStateDidChangeNotification 
     object:nil];

    // When tapping movie, status bar will appear, it shows up
    // in portrait mode by default. Set orientation to   `landscape`                                                                                                                    

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        // Rotate the view for landscape playback
        [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
        [[self view] setCenter:CGPointMake(160, 240)];
        [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

        // Set frame of movie player
        [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];
    } else {
            // Rotate the view for landscape playback
            [[self view] setBounds:CGRectMake(0, 0, 1024, 748)];
            [[self view] setCenter:CGPointMake(374, 512)];
            [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

            // Set frame of movie player
            [[mp view] setFrame:CGRectMake(0.0, 0.0, 1024.0, 748.0)];
        }



        // Add movie player as subview
        [[self view] addSubview:[mp view]];   

        // Play the movie
        [mp play];
    }
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
    // Remove observer
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:nil];

    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:MPMoviePlayerDidExitFullscreenNotification
     object:nil];

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}
4

0 に答える 0