GVKun编程网logo

Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描

3

在本文中,我们将为您详细介绍XcodeSwift5使用AVfoundation扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描的相关知识,此外,我们还会提供一些关于AVAudioToo

在本文中,我们将为您详细介绍Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描的相关知识,此外,我们还会提供一些关于AVAudioToolbox 添加音效 和 AVFoundation 添加播放音乐、AVFoundation - 曝光率没有改变、AVFoundation / AudioKit 播放低频声音会产生点击/弹出、AVFoundation AVCaptureVideoPreviewLayer 在几小时后冻结的有用信息。

本文目录一览:

Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描

Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描

如何解决Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描

我正在学习本教程 http://www.wepstech.com/bar-qr-code-ios-with-swift-5/

添加二维码/条形码扫描仪。

视图从相机捕获开始,当它检测到它打印到控制台

func found(code: String) {
        print(code)
    }

并停止avCaptureSession.stopRunning()

有没有办法添加按钮并在扫描时“暂停”并单击“继续”按钮来扫描另一个框。

在现实生活中(示例),仓库的工作人员收到很多箱子,有时有序列号,但有时是没有序列号的小物品......

所以逻辑是打开扫描仪应用程序,相机开始,扫描->然后暂停->工作人员在下一个框附近更换手机,然后点击恢复。所有这一切都无需相机停止并关闭视图。

所以 2 个问题

•1• 如何在不关闭视图的情况下暂停扫描?

•2• 如何让相机预览不全屏? (添加按钮和文本标签向用户显示扫描的条形码...)

AVAudioToolbox 添加音效 和 AVFoundation 添加播放音乐

AVAudioToolbox 添加音效 和 AVFoundation 添加播放音乐

添加音效

导入#import <AudioToolbox/AudioToolbox.h> 框架

- (void)viewDidLoad {

[super viewDidLoad];

int s=arc4random()%9+1;

NSString* audioFile=[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"duanxin%i.caf",s] ofType:nil];// 获取文件路径

NSURL* url=[NSURL fileURLWithPath:audioFile];// 播放路径

SystemSoundID soundID=0;// 获取声音 ID 初始值

// 步骤 1:创建 系统声音,获得系统声音 ID 和音乐文件链接

AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(url), &soundID);

// 步骤 2:播放

AudioServicesPlayAlertSound(soundID);

// 相当于添加 addTarget 在播放完成之后执行,注册一个回调函数

//P3 回调方法名

AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, addPlayMusic, NULL);

}

 

 

添加播放音乐:

导入#import <AVFoundation/AVFoundation.h> 框架

 

-(void)listPlay{

_musicFeil=[[NSBundle mainBundle] pathForResource:@"第一夫人.mp3" ofType:nil];

NSURL* url=[NSURL fileURLWithPath:_musicFeil];

_player=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];

_player.numberOfLoops=0;//0 播放一次 1 两次 -1:无限次数播放

_player.volume=10;// 音量范围 0-10

[_player prepareToPlay];}

初学,写的粗糙

 

AVFoundation - 曝光率没有改变

AVFoundation - 曝光率没有改变

如何解决AVFoundation - 曝光率没有改变

我正在尝试通过读取平移手势来更改相机的曝光持续时间:

  1. AVCaptureDeviceInput* deviceInput = (AVCaptureDeviceInput*)input;
  2. NSError* error;
  3. if([deviceInput.device isExposurePointOfInterestSupported] && [deviceInput.device isExposureModeSupported:AVCaptureExposureModeCustom]) {
  4. Float64 minexposure = CMTimeGetSeconds([deviceInput.device.activeFormat minexposureDuration]);
  5. Float64 maxExposure = CMTimeGetSeconds([deviceInput.device.activeFormat maxExposureDuration]);
  6. Float64 currentExposure = CMTimeGetSeconds([deviceInput.device exposureDuration]);
  7. Float64 delta = translation.y * (maxExposure - minexposure) + minexposure;
  8. Float64 newExposure = MIN(MAX(currentExposure + delta,minexposure),maxExposure);
  9. [deviceInput.device addobserver:self forKeyPath:@"isAdjustingExposure" options:NSkeyvalueObservingOptionNew context:nil];
  10. [deviceInput.device lockForConfiguration:&error];
  11. [deviceInput.device setExposureMode:AVCaptureExposureModeAutoExpose];
  12. [deviceInput.device setExposurePointOfInterest:focusPoint];
  13. [deviceInput.device setExposureModeCustomWithDuration:CMTimeMake(newExposure,0) ISO:AVCaptureISOCurrent completionHandler:nil];
  14. [deviceInput.device unlockForConfiguration];
  15. }

然后基于 this answer to a previous question 我也在观察“isAdjustingExposure”以在设置时锁定曝光:

  1. - (void)observeValueForKeyPath:(Nsstring *)keyPath
  2. ofObject:(id)object
  3. change:(NSDictionary<NSkeyvalueChangeKey,id> *)change
  4. context:(void *)context {
  5. if([keyPath isEqualToString:@"isAdjustingExposure"]) {
  6. NSNumber* value = [object valueForKey:@"isAdjustingExposure"];
  7. if(value && ![value boolValue]) {
  8. [object setExposureMode:AVCaptureExposureModeLocked];
  9. }
  10. }
  11. }

但由于某种原因,此方法从未被调用。我不确定这最后一步是否有必要,但无论如何这是行不通的,因为我注意到当前的曝光值始终保持不变,而且我还可以从视觉上看到相机没有调整其曝光。

解决方法

键名是 "adjustingExposure" 而不是 "isAdjustingExposure" 并且您的曝光持续时间变为 0/0Float64int64_tCMTimeMake() 中的转换,所以试试

  1. CMTimeMakeWithSeconds(newExposure,10000)

自定义曝光时间

AVFoundation / AudioKit 播放低频声音会产生点击/弹出

AVFoundation / AudioKit 播放低频声音会产生点击/弹出

如何解决AVFoundation / AudioKit 播放低频声音会产生点击/弹出

我正在创建一种鼓垫应用程序,看起来 AKPlayer 是 AudioKit 中用于播放我的样本的许多类中最好的。

问题是,当我开始播放低频(低音音符)样本时,播放样本时总是会发出咔哒声(或“砰”声)!

通过从 AudioKit Playgrounds 运行未经修改的“混合节点”演示,可以轻松听到这一点。调低除低音以外的所有声音的音量,您会注意到每次低音采样循环时都会发出咔嗒声。

我还使用 AVFoundation 测试了该问题,情况也是如此。这只发生在像低音这样的低频声音中。铅和其他声音不会产生这种声音。我还用我自己的低音样本进行了测试,这里也有同样的问题。

这是两者的代码:

import AudioKitPlaygrounds
import AudioKit

import AVFoundation


//: This section prepares the players
let drumFile = try AKAudioFile(readFileName: "drum.wav")
let bassFile = try AKAudioFile(readFileName: "bass.wav")
let guitarFile = try AKAudioFile(readFileName: "guitar.wav")
let leadFile = try AKAudioFile(readFileName: "lead.wav")

var drums = AKPlayer(audioFile: drumFile)
var bass = AKPlayer(audioFile: bassFile)
var guitar = AKPlayer(audioFile: guitarFile)
var lead = AKPlayer(audioFile: leadFile)

bass.play() // will produce click/pop
guitar.play() // will not produce click/pop,only low frequency samples produce click


let path = Bundle.main.path(forResource: "3",ofType:"aac")!
let url = URL(fileURLWithPath: "path")

var bombSoundEffect = try AVAudioPlayer(contentsOf: bassFile.url)
bombSoundEffect.preparetoPlay()

// uncomment below for AVFoundation
// bombSoundEffect.numberOfLoops = -1
// bombSoundEffect.play()

我怎样才能摆脱这种点击/弹出?

解决方法

重新制作您的低音样本,使其开始和结束时都保持沉默。

为了避免循环时的咔嗒声和爆裂声,接缝处的值必须是连续的,即它们不能相差太大。它们的速度也需要匹配,不确定加速度。您可以通过将样本加载到内存中并将其乘以具有上述属性的曲线来轻松实现这一点。开始时从 0 到 1 缓和,然后在结束时返回。

还要在声音编辑器中加载您的样本并检查开头和结尾。可能结局被截断得太厉害了。

AVFoundation AVCaptureVideoPreviewLayer 在几小时后冻结

AVFoundation AVCaptureVideoPreviewLayer 在几小时后冻结

如何解决AVFoundation AVCaptureVideoPreviewLayer 在几小时后冻结

我使用 AVFoundation 来监控使用 AJA U-Tap SDI 接口的视频和音频信号。一切都按预期工作,但长时间后预览会随机冻结。在过去的几周里,我注意到了 2-3 次。它发生在连续预览几个小时之后。没有内存泄漏、控制台消息、警告、会话正在运行,并且所有分配的对象似乎都是有效的。有没有人注意到这样的事情?谢谢。 【macMini,BigSur 11.2.3,最新AJA固件】

解决方法

我假设您使用的是 AVCaptureSession。尝试订阅以下通知以获取线索:

  1. .AVCaptureSessionRuntimeError
  2. .AVCaptureSessionDidStopRunning
  3. .AVCaptureDeviceWasDisconnected
  4. .AVCaptureInputPortFormatDescriptionDidChange

我们今天的关于Xcode Swift 5 使用 AVfoundation 扫描条码,如何在不停止或关闭视图的情况下暂停和添加按钮以继续扫描的分享就到这里,谢谢您的阅读,如果想了解更多关于AVAudioToolbox 添加音效 和 AVFoundation 添加播放音乐、AVFoundation - 曝光率没有改变、AVFoundation / AudioKit 播放低频声音会产生点击/弹出、AVFoundation AVCaptureVideoPreviewLayer 在几小时后冻结的相关信息,可以在本站进行搜索。

本文标签: