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

Found the solution for this problem. In my app, I had to override the mute switch, so I added the code in AppDelegate.m

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

Due to this category, iPhone 4 volume output was low. I changed the code to

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

Now, it works fine. Though, I still can't understand why was the sound output low only on iPhone 4 and not any other device like iPad, iPhone 5.

于 2013-06-24T06:51:53.113 に答える