使用Appcelerator Titanium录制Android和iOS的音频

时间:2018-08-30 04:00:11

标签: titanium appcelerator

我在尝试将音频记录到文件时遇到问题。我正在尝试运行示例代码(在tiapp.xml中具有所需的权限),但是我总是遇到错误(例如“ + [NSBlock boundBridge:withKrollObject:]:无法识别的选择器发送给类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();

预先感谢