簡體   English   中英

除iPhone 4以外,所有iOS設備上的音量都很好。在iPhone上,音量非常低

[英]Volume level fine on all iOS devices EXCEPT the iPhone 4. On iPhone the level is very low

我正在開發可在所有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];

由於該類別,iPhone 4的音量輸出較低。 我將代碼更改為

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

現在,它工作正常。 雖然,我仍然不明白為什么聲音輸出僅在iPhone 4而不是在其他任何設備(如iPad,iPhone 5)低。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM