// introVideoViewController
#import <AVFoundation/AVAudioSession.h>
#import <AudioToolbox/AudioServices.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <MediaPlayer/MediaPlayer.h>
@property(nonatomic,strong) MPMoviePlayerController *playercontroller;
嗨,大家好,
任何人都知道在iOS 7中我能听到我的视频声音而不是视频,它在iOS 6中运行良好。
非常感谢任何评论。
// introVideoViewController
//prepare & init video
-(void)prepareIntroVideo
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"intro_movie" ofType:@"mp4"]];
//NSURL *url = [NSURL URLWithString:@"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
self.playercontroller = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.playercontroller.view setFrame:CGRectMake(0, 0, 320,480)];
self.playercontroller.movieSourceType = MPMovieSourceTypeFile;
self.playercontroller.scalingMode = MPMovieScalingModeAspectFill;
self.playercontroller.fullscreen = YES;
self.playercontroller.controlStyle = MPMovieControlStyleNone;
//playercontroller.controlStyle = MPMovieControlStyleFullscreen;
self.playercontroller.view.userInteractionEnabled =NO;
self.playercontroller.view.backgroundColor = [UIColor blackColor];
self.playercontroller.shouldAutoplay = NO;
//playercontroller.repeatMode = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.playercontroller];
[self.playercontroller prepareToPlay];
[self.view addSubview:self.playercontroller.view];
// get the handle
// Get the result
self.firstlaunchVideoCheck = [self.defaults stringForKey:@"firstlaunchVideo"];
//NSLog(@"first launch null or 1 = %@",firstlaunchVideoCheck);
if ([self.firstlaunchVideoCheck intValue])
{
//skip view overlay
UIView *skipView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
UITapGestureRecognizer *singleTapping =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showSkipButton)];
singleTapping.delegate =self;
singleTapping.numberOfTapsRequired = 1;
[skipView addGestureRecognizer:singleTapping];
singleTapping.cancelsTouchesInView = NO;
//skipbutton
self.skipMovieButton = [UIButton buttonWithType:UIButtonTypeCustom];
//0, 276, 480, 54)
if (isPhone568)
{
[self.skipMovieButton setFrame:CGRectMake(227, 504, 92, 44)];
}
else
{
[self.skipMovieButton setFrame:CGRectMake(227, 436, 92, 44)];
}
[self.skipMovieButton setBackgroundColor:[UIColor clearColor]];
UIImage *skipMovieButtonNormal = [UIImage imageNamed:@"button_skip.png"];
//UIImage *skipMovieButtonPress = [UIImage imageNamed:@"skip-(active).png"];
[self.skipMovieButton setBackgroundImage:skipMovieButtonNormal forState:UIControlStateNormal];
//[self.skipMovieButton setBackgroundImage:skipMovieButtonPress forState:UIControlStateHighlighted];
[self.skipMovieButton addTarget:self action:@selector(skipMovie) forControlEvents:UIControlEventTouchUpInside];
[skipView addSubview:self.skipMovieButton];
[self.view addSubview:skipView];
}
[self.playercontroller stop];
[self.view bringSubviewToFront:self.titleImgView];
[self.view bringSubviewToFront:self.startMovieButton];
[self.view sendSubviewToBack:self.playercontroller.view];
[self.view sendSubviewToBack:self.skipMovieButton];
}
//play video
-(void)playIntroVideo
{
NSLog(@"self.playercontroller.playbackState %i",self.playercontroller.playbackState);
if (self.playercontroller.playbackState == MPMoviePlaybackStatePlaying)
{
NSLog(@"playerconroller playing, do nothing");
}
else if (self.playercontroller.playbackState == MPMoviePlaybackStateStopped)
{
NSLog(@"playerconroller playing, do nothing11111111111");
[self.playercontroller play];
}
}
//called when video played completed
- (void)moviePlaybackComplete:(NSNotification *)notification
{
////NSLog(@"Here Got Called");
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
//[playercontroller.view removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationWillEnterForegroundNotification
object:[UIApplication sharedApplication]];
if (![self.firstlaunchVideoCheck intValue])
{
self.firstlaunchVideoCheck = @"1";
// get the handle
[self.defaults setObject:self.firstlaunchVideoCheck forKey:@"firstlaunchVideo"];
// save it
[self.defaults synchronize];
}
[self skipMovie];
}
答案 0 :(得分:3)
添加一行后,一切正常。
self.playercontroller.contentURL = url;