简体   繁体   English

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

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

I am developing an iOS app that runs on all iOS devices. 我正在开发可在所有iOS设备上运行的iOS应用。 In my app, I am playing some video files. 在我的应用中,我正在播放一些视频文件。 Everything works fine on all devices except for iPhone 4. On iPhone4, volume level is very low even though all other apps work with normal volume level on that device. 除了iPhone 4以外,所有其他设备上的所有设备都运行正常。在iPhone4上,即使所有其他应用程序在该设备上以正常音量运行,音量也非常低。 On all other devices, volume level is fine. 在所有其他设备上,音量都可以。 Can anybody please help me with this trouble? 有人可以帮我解决这个麻烦吗? Thanks in advance. 提前致谢。

Here is the source code 这是源代码

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];

Here is the code for getVideoToBePlayedForButtonTag message: 这是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;

} }

Found the solution for this problem. 找到了解决此问题的方法。 In my app, I had to override the mute switch, so I added the code in AppDelegate.m 在我的应用程序中,我必须覆盖静音开关,因此我在AppDelegate.m中添加了代码

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

Due to this category, iPhone 4 volume output was low. 由于该类别,iPhone 4的音量输出较低。 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. 虽然,我仍然不明白为什么声音输出仅在iPhone 4而不是在其他任何设备(如iPad,iPhone 5)低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM