record

录音组件 首次使用请先执行:weexplus plugin add https://github.com/farwolf2010/record

API

  1. /**
  2. * 开始
  3. * @param param {channel:'mono',quality:'low','high'}
  4. */
  5. show(param)
  6. /**
  7. *暂停
  8. */
  9. pause()
  10. /**
  11. *停止
  12. */
  13. stop(callback)

DEMO

  1. <template>
  2. <div style="align-items: center;justify-content: center">
  3. <video style="width: 500px;height: 300px;background-color: red" auto-play="true" :src="src"></video>
  4. <button @click="start" text="start" style="margin-top: 20px"></button>
  5. <button @click="pause" text="pause" style="margin-top: 20px"></button>
  6. <button @click="stop" text="stop" style="margin-top: 20px"></button>
  7. <text>{{text}}</text>
  8. </div>
  9. </template>
  10. <script>
  11. export default{
  12. props: {},
  13. data () {
  14. return {
  15. text:'',
  16. src:''
  17. }
  18. },
  19. methods: {
  20. onLoad(){
  21. },
  22. start(){
  23. // let audio=weex.requireModule('audio')
  24. // audio.play('http://192.168.0.102:8890/js/1.wav')
  25. // return
  26. let record=weex.requireModule('record')
  27. record.start({channel:'mono',quality:'high'})
  28. },
  29. pause(){
  30. let record=weex.requireModule('record')
  31. record.pause()
  32. },
  33. stop(){
  34. let record=weex.requireModule('record')
  35. record.stop((res)=>{
  36. this.text=res
  37. this.src=res.path
  38. // this.upload(this.src)
  39. // let audio=weex.requireModule('audio')
  40. // audio.play(this.src)
  41. })
  42. },
  43. upload(pathx){
  44. var param={};
  45. var header={
  46. };
  47. var path={};
  48. path.file=pathx;
  49. var net=weex.requireModule("net");
  50. var process=weex.requireModule("process");
  51. net.postFile('http://59.110.169.246/movie/imgupload.do',param,header,path,()=>{
  52. //start
  53. // process.show()
  54. },(e)=>{
  55. //succcess
  56. var modal=weex.requireModule("modal")
  57. modal.toast({message:'上传成功!'})
  58. },()=>{
  59. //compelete
  60. // process.dismiss()
  61. },()=>{
  62. //exception
  63. var modal=weex.requireModule("modal")
  64. modal.toast({message:'上传异常!'})
  65. })
  66. }
  67. },
  68. mounted () {
  69. },
  70. created () {
  71. }
  72. }
  73. </script>
  74. <style scoped>
  75. </style>