【问题标题】:Record Audio for Android and iOS using Appcelerator Titanium使用 Appcelerator Titanium 为 Android 和 iOS 录制音频
【发布时间】:2018-08-30 04:00:11
【问题描述】:

我在尝试将音频录制到文件时遇到问题。我正在尝试运行示例代码(在 tiapp.xml 中具有所需的权限),但我总是遇到错误(例如“+[NSBlock boundBridge:withKrollObject:]: unrecognized selector sent to class 0x1b5549500”; 在停止() 动作)。

我找不到用于录音的模块(我使用了 tutorial.audiorecord,但它在最新版本的 SDK 中不起作用)

这是来自 appcelerator 文档页面 https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media.AudioRecorder 的示例代码

我尝试了所有方法但没有用。

有人有 Appcelerator SDK 7 的工作示例或模块吗?

var window = Ti.UI.createWindow({
  backgroundColor: '#fff'
});

var recordStart = Ti.UI.createButton({
  title: 'Start',
  top: 10
});

var recordPause = Ti.UI.createButton({
  title: 'Pause',
  top: 60
});

var recordStop = Ti.UI.createButton({
  title: 'Stop',
  top: 110
});

var recordPlay = Ti.UI.createButton({
  title: 'Play',
  top: 160
});

var audioRecorder = Ti.Media.createAudioRecorder();

var record;
var audioPlayer;

window.addEventListener('open', function(e) {
  if (!Ti.Media.hasAudioRecorderPermissions()) {
    Ti.Media.requestAudioRecorderPermissions(function(e) {
      if (e.success) {
        window.add(recordStart);
      }
    });
  } else {
    window.add(recordStart);
  }
});

recordStart.addEventListener('click', function(e) {
  audioRecorder.start();
});

recordPause.addEventListener('click', function(e) {
  if (audioRecorder.getPaused()) {
    recordPause.setTitle('Pause');
    audioRecorder.resume();
  } else {
    recordPause.setTitle('Resume');
    audioRecorder.pause();
  }
});

recordStop.addEventListener('click', function(e) {
  record = audioRecorder.stop();
  Ti.API.info(record.getNativePath());
});

recordPlay.addEventListener('click', function(e) {
  audioPlayer = Ti.Media.createAudioPlayer({
    url: record.getNativePath()
  });
  audioPlayer.start();
});

window.add(recordPause);
window.add(recordStop);
window.add(recordPlay);

window.open();

提前致谢

【问题讨论】:

标签: titanium appcelerator


【解决方案1】:

这是使用 Titanium 的 Hyperloop 的示例:https://gist.github.com/dinahgarcia/119ac00c91334d3951601cf347bad8d4 要使用它,您需要启用 Hyperloop:https://docs.appcelerator.com/platform/latest/#!/guide/Enabling_Hyperloop

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多