美文网首页
cordova-plugin-media简单使用

cordova-plugin-media简单使用

作者: docC2Y | 来源:发表于2016-08-26 15:11 被阅读4553次

    在代码所在文件夹外出命令行cordova plugin add  cordova-plugin-media,即可完成插件的安装。

    Methods:

    media.getCurrentAmplitude: Returns the current position within an audio file.

    media.getCurrentPosition: Returns the current position within an audio file.

    media.getDuration: Returns the duration of an audio file.

    media.play: Start or resume playing an audio file.

    media.pause: Pause playback of an audio file.

    media.pauseRecord: Pause recording of an audio file.

    media.release: Releases the underlying operating system's audio resources.

    media.resumeRecord: Resume recording of an audio file.

    media.seekTo: Moves the position within the audio file.

    media.setVolume: Set the volume for audio playback.

    media.startRecord: Start recording an audio file.

    media.stopRecord: Stop recording an audio file.

    media.stop: Stop playing an audio file.

    录音record部分:

    var src = "myrecording.wav";

    var mediaRec = new Media(src,

               function () {

                        UiMsg.toast("record succ");

               },

                function (err) {

                        UiMsg.toast("record fail:"+ err.code);

                });

    录音的命名需以.wav结尾(ios上测试一.mp3结尾不识别)。

    mediaRec.startRecord();

    开始录音。

    mediaRec.stopRecord();

    结束录音。

    mediaRec.play();

    播放录音。

    mediaRec.getDuration();

    获取文件时长。

    已知文件播放:

    // Play audio

    //

    function playAudio(url) {// Play the audio file at url

                      var my_media = new Media(url,         // success callback

                                    function () {

                                              console.log("playAudio():Audio Success");

                                    },

                                          / / error callback

                                    function (err) {

                                                console.log("playAudio():Audio Error: " + err);

                                     }

    );

                      // Play audio

                     my_media.play();

    }

    order of file search: When only a file name or simple path is provided, iOS searches in the www directory for the file, then in the application's documents/tmp directory:

    var myMedia = new Media("audio/beer.mp3")

    myMedia.play()  // first looks for file in www/audio/beer.mp3 then in /documents/tmp/audio/beer.mp3

    相关文章

      网友评论

          本文标题:cordova-plugin-media简单使用

          本文链接:https://www.haomeiwen.com/subject/wqlzsttx.html