2
votes

Our app records and plays (those) videos. But somehow some of the videos are played without sound.

If i copy the video files to the mac via iTunes it plays the videos with sound, so the videos do have sound.

I checked the videos with a tool (called GSpot) and they all have the same audio codec and bitrate.

I tried about everything i found on SO but some of the videos dont play audio and the code is always the same and the videos do have sound as on a mac you can hear it.

This is how i setup the player

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

some time later, on a button press, it starts playing.

The record settings

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

I dont know if it is related but the audio seems to not play on videos that had a different view overlayed during the recording. It is possible to overlay a fullscreen view over the video preview while recording and it records fine and the file itself has audio and they play fine on a pc/mac... only on the device within our app those videos (again, not sure if related) have no audio. App uses same code for every video, so i can rename them, swap them etc, the behaviour has something to do with the audio channel of the video.

edit

Additional observation: The vids where there is no sound, quicktime (only on mac) also plays no audio. QT on windows does play audio and all other players on windows do play audio as well. Somehow the phone corrupts its own recording so that afterwards it doesnt recognize the audio channel it just recorded

edit 2

iPhone 6, iOS 8.1beta 2 -> as described iPhone 4S, iOS 7.1.2 -> NO issue iPad mini, iOS 8.0.2 -> always has the issue, not one videos audio channel can be read, but always exists and windows can play audio

1

1 Answers

2
votes

I want to wrap this up.

The file was saved as ".mp4" and this causes the sporadic error. Saving the file as ".mov" works. Same codec etc but without errors.

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

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

[mAVCaptureMovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];