1

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

}

4

1 回答 1

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 等任何其他设备都没有。

于 2013-06-24T06:51:53.113 回答