Ionic, how can I create an mp3 file?

I am writing a web application with a framework Ionicand I am trying to control the mechanism for recording and playing sounds. As a service, I use the following snippet:

.factory('MediaSrv', function ($q, $ionicPlatform, $window) {
    var service = {
        loadMedia: loadMedia,
        getStatusMessage: getStatusMessage,
        getErrorMessage: getErrorMessage
    };

    function loadMedia (src, onError, onStatus, onStop) {
        var defer = $q.defer();

        $ionicPlatform.ready(function () {
            var mediaSuccess = function () {
                if (onStop) { onStop(); }
            };

            var mediaError = function (err) {
                _logError(src, err);
                if (onError) { onError(err); }
            };

            var mediaStatus = function (status) {
                if (onStatus) { onStatus(status); }
            };

            if ($ionicPlatform.is('android')) {
                src = '/android_asset/www/' + src;
            }

            defer.resolve(new $window.Media(src, mediaSuccess, mediaError, mediaStatus));
        });

        return defer.promise;
    }

    ...

    return service;
});

I can play an existing file .mp3, but I cannot write it to a nonexistent file. I thought it would create the file by itself if the file could not be found. How can I create an empty file .mp3for writing?

+4
source share
2 answers

File creation is a server feature. To create the file you will need a node server using fs .

From the Ionic website:

Ionic , , , . "Bootstrap for Native", , .

+1

Cordova, .

- , AMR.

[] [1]:

// capture callback
var captureSuccess = function(mediaFiles) {
    var i, path, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        path = mediaFiles[i].fullPath;
        // do something interesting with the file
    }
};

// capture error callback
var captureError = function(error) {
    navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};

// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});


  [1]: http://docs.phonegap.com/en/edge/cordova_media_capture_capture.md.html
0

Source: https://habr.com/ru/post/1568443/


All Articles