2014-10-20 49 views
2

我们的应用程序会记录和播放(那些)视频。但不知何故,某些视频播放时没有声音。应用程序录制的视频在手机上播放时有时不播放音频

如果我通过iTunes将视频文件复制到mac,它会播放带声音的视频,因此视频确实有声音。

我用一种工具(称为GSpot)检查了视频,它们都具有相同的音频编解码器和比特率。

我尝试了所有我发现的东西,但有些视频不播放音频,代码总是相同,并且视频在Mac上可以听到它的声音。

这是玩家

AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
NSError *setCategoryError = nil; 
[audioSession setActive:YES error:&setCategoryError]; 
[audioSession setCategory:AVAudioSessionCategoryPlayback 
          error:&setCategoryError]; 

_mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviepath]]; 

_mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
_mpviewController.moviePlayer.controlStyle  = MPMovieControlStyleNone; 
[_mpviewController.moviePlayer setScalingMode:MPMovieScalingModeAspectFill]; 

_mpviewController.moviePlayer.shouldAutoplay = YES; 

[_mpviewController.moviePlayer prepareToPlay]; 

_mpviewController.view.frame = CGRectMake(0, 0, _screenWidth, _screenHeight); 

[self addSubview:_mpviewController.view]; 

一段时间后,就按下按钮,启动我怎么设置播放。

的记录设置

[_session beginConfiguration]; 

[_session setSessionPreset: AVCaptureSessionPreset640x480]; 

AVCaptureDevice * videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
BOOL lock = [videoDevice lockForConfiguration:&error]; 
if(lock) videoDevice.focusMode = AVCaptureFocusModeContinuousAutoFocus; 
[videoDevice unlockForConfiguration]; 

if(videoDevice == nil){ 
    assert(0); 
} 

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; 
if(error){ 
    assert(0); 
} 

[_session addInput:input]; 

AVCaptureDevice *audioDevice  = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; 
AVCaptureDeviceInput * audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil]; 
if(audioInput != nil) { 
    [_session addInput:audioInput]; 
} 

[_session commitConfiguration]; 

我不知道这是否是相关的,但声音似乎不上有记录过程中叠加了不同的看法的视频播放。在录制时可以在视频预览上叠加全屏视图,并且录制得很好,文件本身也有音频,并且可以在PC/Mac上正常播放...只在应用程序内的设备上显示这些视频(再次,不确定如果相关的话)没有音频。应用程序为每个视频使用相同的代码,因此我可以重命名它们,交换它们等,这种行为与视频的音频通道有关。

编辑

附加观察: 的VIDS那里是没有声音的QuickTime(仅在Mac)也发挥没有音讯。 QT在Windows上播放音频,而Windows上的其他播放器也播放音频。 不知何故电话破坏了自己的记录,以便事后它不承认它只是记录

编辑2

iPhone 6的音频通道,的iOS 8.1beta 2 - >描述 iPhone 4S的,的iOS 7.1。 2 - >没有问题 iPad mini,iOS 8.0.2 - >总是有问题,没有一个视频音频通道可以读取,但始终存在,Windows可以播放音频

回答

2

我想包装起来。

该文件被保存为“.mp4”,这导致零星的错误。 将文件保存为“.mov”。相同的编解码器等,但没有错误。

NSString *path = [[documentsDirectoryPath stringByAppendingPathComponent: 
    [NSString stringWithFormat:@"/%@", name]] stringByAppendingString:@".mov"]; 

outputURL = [[NSURL alloc] initFileURLWithPath:path]; 

[mAVCaptureMovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];