除iPhone 4外,所有iOS设备的音量级别都很好.在iPhone上,这个级别非常低



我正在开发一款在所有iOS设备上运行的iOS应用程序。在我的应用程序中,我正在播放一些视频文件。除iPhone 4外,所有设备都能正常工作。在iPhone4上,音量水平非常低,即使所有其他应用程序在该设备上都以正常音量水平工作。在所有其他设备上,音量级别都可以。有人能帮我解决这个麻烦吗?提前谢谢。

这是的源代码

NSInteger selectedVideoTag = sender.tag;
NSString *videoPath = [self getVideoToBePlayedForButtonTag:selectedVideoTag];
NSURL *videoUrl = [[NSURL alloc] initFileURLWithPath:videoPath];
NSLog(@"videoUrl = %@", videoUrl);
self.theMovie = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:self.theMovie];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlaybackStateChaned:)
                                             name:MPMoviePlayerWillExitFullscreenNotification
                                           object:self.theMovie];

[self.theMovie prepareToPlay];
[self.theMovie.view setFrame:[[UIScreen mainScreen] bounds]];

[self.view addSubview:self.theMovie.view];
self.theMovie.controlStyle = MPMovieControlStyleDefault;
[self.theMovie setFullscreen:YES animated:YES];
[self.theMovie setScalingMode:MPMovieScalingModeAspectFill];
self.theMovie.movieSourceType = MPMovieSourceTypeFile;
[self.theMovie play];

以下是getVideoToBePlayedForButtonTag消息的代码:

- (NSString *) getVideoToBePlayedForButtonTag:(NSInteger)btnTag
{
NSString *videoPath = nil;
//Trigger MixPanel events for selected button
Mixpanel *mixPanel = [Mixpanel sharedInstance];
switch (btnTag) {
    case 1:
        videoPath =[[NSBundle mainBundle] pathForResource:@"song_01" ofType:@"mp4"];
        break;
    case 2:
        videoPath =[[NSBundle mainBundle] pathForResource:@"song_02" ofType:@"mp4"];
        break;
    case 3:
        videoPath =[[NSBundle mainBundle] pathForResource:@"song_03" ofType:@"mp4"];
        break;
    case 4:
        videoPath =[[NSBundle mainBundle] pathForResource:@"song_04" ofType:@"mp4"];
        break;
    default:
        break;
}
return videoPath;

}

找到了这个问题的解决方案。在我的应用程序中,我必须覆盖静音开关,所以我在AppDelegate.m 中添加了代码

NSError *categoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&categoryError];

由于这一类别,iPhone4的产量很低。我把代码改成

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&categoryError];

现在,它运行良好。尽管如此,我仍然不明白为什么只有iPhone 4的声音输出很低,而iPad、iPhone 5等其他设备的声音输出却很低。

相关内容

最新更新