Skip to content

Commit

Permalink
fix permission bug
Browse files Browse the repository at this point in the history
  • Loading branch information
huangminlinux committed May 11, 2017
1 parent e971d8e commit 92852ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
7 changes: 5 additions & 2 deletions iOS/IMUI/Views/IMUIInputView/Views/IMUICameraCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ class IMUICameraCell: UICollectionViewCell, IMUIFeatureCellProtocal {

func inactivateMedia() {
isActivity = false
if videoFileOutput!.isRecording {
videoFileOutput?.stopRecording()

if let videofile = videoFileOutput {
if videofile.isRecording {
videoFileOutput?.stopRecording()
}
}

self.session.stopRunning()
Expand Down
52 changes: 34 additions & 18 deletions iOS/IMUI/Views/IMUIInputView/Views/IMUIRecordVoiceCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit

import AVFoundation

class IMUIRecordVoiceCell: UICollectionViewCell, IMUIFeatureCellProtocal {
static var buttonNormalWith: CGFloat = 46.0
Expand Down Expand Up @@ -72,30 +72,46 @@ class IMUIRecordVoiceCell: UICollectionViewCell, IMUIFeatureCellProtocal {
}

@IBAction func startRecordVoice(_ sender: Any) {
self.swtichToPlayModeBtn.isHidden = false
self.cancelVoiceBtn.isHidden = false

UIView.animate(withDuration: 0.2) {
self.contentView.layoutIfNeeded()

switch AVAudioSession.sharedInstance().recordPermission() {
case AVAudioSessionRecordPermission.granted:
self.swtichToPlayModeBtn.isHidden = false
self.cancelVoiceBtn.isHidden = false

UIView.animate(withDuration: 0.2) {
self.contentView.layoutIfNeeded()
}

recordHelper.startRecordingWithPath(self.getRecorderPath(),
startRecordCompleted: {

}) { (duration, meter) in
let seconds = Int(duration)
self.timeLable.text = "\(String(format: "%02d", seconds / 60)):\(String(format: "%02d", seconds % 60))"

}
case AVAudioSessionRecordPermission.denied:
break
case AVAudioSessionRecordPermission.undetermined:
break
default:
break
}

recordHelper.startRecordingWithPath(self.getRecorderPath(),
startRecordCompleted: {

}) { (duration, meter) in
let seconds = Int(duration)
self.timeLable.text = "\(String(format: "%02d", seconds / 60)):\(String(format: "%02d", seconds % 60))"

}

}

func finishRecordVoice() {
self.swtichToPlayModeBtn.isHidden = true
self.cancelVoiceBtn.isHidden = true
self.resetSubViewsStyle()
if AVAudioSession.sharedInstance().recordPermission() == .granted {
self.swtichToPlayModeBtn.isHidden = true
self.cancelVoiceBtn.isHidden = true
self.resetSubViewsStyle()

let finishiRecorder = recordHelper.finishRecordingCompletion()
self.inputViewDelegate?.finishRecordVoice(finishiRecorder.voiceFilePath, durationTime: finishiRecorder.duration)
}

let finishiRecorder = recordHelper.finishRecordingCompletion()
self.inputViewDelegate?.finishRecordVoice(finishiRecorder.voiceFilePath, durationTime: finishiRecorder.duration)
}

func resetSubViewsStyle() {
Expand Down

0 comments on commit 92852ff

Please sign in to comment.