所有iOS设备上的音量都很好,除了iPhone 4.在iPhone上,音量非常低

时间:2013-06-22 05:47:54

标签: iphone ios objective-c ipad

我正在开发一个可在所有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;

}

1 个答案:

答案 0 :(得分:0)

找到解决此问题的方法。 在我的应用程序中,我不得不覆盖静音开关,所以我在AppDelegate.m中添加了代码

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

由于此类别,iPhone 4的音量输出很低。 我将代码更改为

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

现在,它运作正常。虽然,我仍然无法理解为什么声音输出仅在iPhone 4而不是iPad,iPhone 5等任何其他设备上都很低。