Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record stop method error #135

Open
yoking-shi opened this issue Nov 30, 2018 · 2 comments
Open

record stop method error #135

yoking-shi opened this issue Nov 30, 2018 · 2 comments

Comments

@yoking-shi
Copy link

yoking-shi commented Nov 30, 2018

this is the error:
image

my code:

<template>
  <Page class="page">
    <ActionBar class="action-bar">
      <Label class="action-bar-title"
             text="Home"></Label>
    </ActionBar>
    <StackLayout backgroundColor="#3c495e">
      <Label>{{ recording ? '录音中' : '' }}</Label>

      <button @tap="start">开始</button>
      <button @tap="stop">关闭</button>
      <button @tap="play">播放</button>

    </StackLayout>
  </Page>
</template>

<script>
import * as Audio from 'nativescript-audio'
import { File, knownFolders } from 'tns-core-modules/file-system'
export default {
  data () {
    return {
      player: new Audio.TNSPlayer(),
      recorder: new Audio.TNSRecorder(),
      recording: false,
      audioPath: `${knownFolders.currentApp().getFolder('audio').path}/record.mp3`
    }
  },

  mounted() {
    this.recorder.debug = true
  },

  methods: {
    start () {
      console.log('aysnc start >>>>>>>>>>>>>>>>>> start')
      const options = {
        filename: this.audioPath,
        metering: true,
        infoCallback: infoObject => {
          console.log('record-infoCallBack', JSON.stringify(infoObject));
        },
        errorCallback: errorObject => {
          console.log('record-errorCallback', JSON.stringify(errorObject));
        }
      }

      this.recorder.start(options).catch(ex => {
        console.log(ex)
      })
      this.recording = true
      console.log('aysnc start >>>>>>>>>>>>>>>>>> end')
    },

    stop () {
      console.log('stop>>>>>>>>>>>>>>>>>>')
      console.log(this.audioPath)
      this.recorder.stop().catch(ex => {
        console.log(ex)
      })
      this.recording = false
    },

    play () {
      console.log('play>>>>>>>>>>>>>>>>>>')
      const options = {
        audioFile: this.audioPath,
        loop: false,
        completeCallback: () => {
          alert('Audio file complete.')
        },
        errorCallback: errorObject => {
          console.log(JSON.stringify(errorObject))
        },
        infoCallback: infoObject => {
          console.log(JSON.stringify(infoObject))
        }
      }

      this.player.playFromFile(options).catch(err => {
        console.log('error playFromFile', err)
      })
    }
  }
}
</script>

<style scoped lang="scss">
// Start custom common variables
@import "../app-variables";
// End custom common variables

// Custom styles
.fa {
  color: $accent-dark;
}

.info {
  font-size: 20;
}
</style>

How to set encode and format? Any examples of parameters?
image
thank you :)

@cmckni3
Copy link
Contributor

cmckni3 commented Jan 4, 2019

are you using vue.js? should it be something like this for your data and mounted?

export default {
  data: function() {
    return {
      player: new Audio.TNSPlayer(),
      recorder: new Audio.TNSRecorder(),
      recording: false,
      audioPath: `${knownFolders.currentApp().getFolder('audio').path}/record.mp3`
    }
  },

  mounted: function() {
    this.recorder.debug = true
  },
...
}

@progressify
Copy link

progressify commented Jan 5, 2019

Hi @yoking-shi
I have read (I don't remember where xD), you must set manually the value you want to use, you can see all value on this page: https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder
for example 3 for AAC encoding: https://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder.html#AAC

bye 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants