【问题标题】:How to record audio and playback on Ionic 2?如何在 Ionic 2 上录制音频和播放?
【发布时间】:2016-11-26 00:42:17
【问题描述】:

我目前正在开发一个 Ionic 2 应用程序项目,该项目允许用户录制自己的声音、停止录制并播放该声音。根据 ionic-native,我可以看到他们提供了 2 个插件,即 MediaPlugin 和 MediaCapture。我尝试过使用 MediaPlugin,但在开始录制、停止并播放时遇到了问题。 有人用过这个插件吗?我浏览了离子文档和其他一些博客,但我仍然无法做到。我对此很陌生,非常感谢您的努力。我很欣赏你的所有想法。

问候,

这是我在开始录制时从模拟器获得的日志:

I/MPEG4Writer(  401): limits: 2147483647/0 bytes/us, bit rate: 12200 bps and the estimated moov size 3072 bytes
D/Genyd   (   56): Received Set Clipboard
D/Genymotion(   56): Received Set Clipboard
D/dalvikvm(  379): GC_CONCURRENT freed 717K, 13% free 6011K/6864K, paused 0ms+1ms, total 10ms
E/genymotion_audio(  401): get_next_buffer() pcm_read error -1
W/PluginManager( 1116): THREAD WARNING: exec() call to Media.startRecordingAudio blocked the main thread for 10037ms. Plugin should use CordovaInterface.getThreadPool().
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
I/MPEG4Writer(  401): setStartTimestampUs: 10031588
I/MPEG4Writer(  401): Earliest track starting time: 10031588
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
E/genymotion_audio(  401): get_next_buffer() pcm_read error -16

这是我在停止录制时从模拟器获得的日志:

 I/MPEG4Writer(  401): Received total/0-length (42/0) buffers and encoded 42 frames. - audio
    I/MPEG4Writer(  401): Audio track drift time: 0 us
    D/MPEG4Writer(  401): Stopping Audio track source
    E/genymotion_audio(  401): get_next_buffer() pcm_read error -16
    D/MPEG4Writer(  401): Audio track stopped
    D/MPEG4Writer(  401): Stopping writer thread
    D/MPEG4Writer(  401): 0 chunks are written in the last batch
    D/MPEG4Writer(  401): Writer thread stopped
    I/MPEG4Writer(  401): The mp4 file will not be streamable.
    D/MPEG4Writer(  401): Stopping Audio track
    D/AudioPlayer( 1116): renaming /storage/emulated/0/tmprecording.3gp to /storage/emulated/0/../Documents/undefined-.wav
    E/AudioPlayer( 1116): FAILED renaming /storage/emulated/0/tmprecording.3gp to /storage/emulated/0/../Documents/undefined-.wav
    W/PluginManager( 1116): THREAD WARNING: exec() call to Media.stopRecordingAudio blocked the main thread for 135ms. Plugin should use CordovaInterface.getThreadPool().

这是我的 home.ts 代码:

import {Component} from '@angular/core';
import {NavController, Platform, Page, Events} from 'ionic-angular';
import {MediaPlugin} from 'ionic-native';

@Component({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
    private _platform: Platform;
    private _fileRecord: MediaPlugin;
    private _pathFile: string;
    private _nameFile: string;
  constructor(private navCtrl: NavController, platform: Platform) {
     this._platform = platform;
  }
  public startRecord(): void {
     this._pathFile = this.getPathFileRecordAudio();
     this._fileRecord = new MediaPlugin(this._pathFile);
     this._fileRecord.startRecord();
  }

  public stopRecord(): void {
     this._fileRecord.stopRecord();
  }

  private startPlay(): void {
     this._fileRecord = new MediaPlugin(this._pathFile);
     this._fileRecord.play();
  }

  private getPathFileRecordAudio(): string {
     let path: string = (this._platform.is('ios') ? '../Library/NoCloud/': '../Documents/');
     return path + this._nameFile + '-' + '.wav';
  }
 }

【问题讨论】:

    标签: audio typescript ionic-framework audio-recording ionic2


    【解决方案1】:

    您是否检查了 source 中的 cmets 以获取该插件?有关于如何调整事情的注释......有人有类似的here,但您提供了与错误有关的更多细节。 (我将 cmets 复制到该答案中)。

    【讨论】:

      猜你喜欢
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多