###前提・実現したいこと
monacaのクラウドIDEを利用しています。
音楽プレイヤーを作ろうとしていて、外部ファイルを読み込みたいのでcordovaのFileプラグインが使いたいです。
クラウドIDEでプラグインを有効にしても下記のエラーが出ます。
開発環境を変えてプラグインを有効にするとエラーが出ないようです。
開発環境は変えたくないのですが、クラウドIDE以外の方法でcordovaプラグインを有効にする方法はあるでしょうか?
###発生している問題・エラーメッセージ
cordovaプラグインのFileを有効にしているのですが、Uncaught TypeError: window.requestFileSystem is not a functionと出ます。
###該当のソースコード
<!DOCTYPE HTML> <html id="myApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'"> <script src="lib/angular/angular.min.js"></script> <script src="lib/onsenui/js/onsenui.min.js"></script> <script src="lib/onsenui/js/angular-onsenui.min.js"></script> <script src="components/loader.js"></script> <link rel="stylesheet" href="components/loader.css"> <link rel="stylesheet" href="lib/onsenui/css/onsenui.css"> <link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css"> <link rel="stylesheet" href="css/style.css"> <script> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { //alert("Fileプラグインが利用できます。"); window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; //window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error); var grantedBytes = 0;// 1024*1024*10; // 10MB window.requestFileSystem(PERSISTENT, grantedBytes, /*$scope.*/fileSystemReceived, /*$scope.*/errorHandler); } myApp = ons.bootstrap(); myApp.controller('AppController', function($scope) { this.load = function(page) { $scope.splitter.content.load(page); $scope.splitter.left.close(); }; this.toggle = function() { $scope.splitter.left.toggle(); }; }); myApp.controller("SampleController", ["$scope", "FileSystem", function($scope, FileSystem){ FileSystem.getFileSystem() .then(function(fs){ $scope.ROOT_PATH = fs.root.toURL(); /* ルートへのパスを取得 */ }, function(error){ alert("エラーです"); }); $scope.fileSystemReceived = function (fileSystem) { fileSystem.root.getFile("souvenirs.json", { create: true, exclusive: false }, $scope.fileEntryReceived, $scope.errorHandler); } $scope.fileEntryReceived = function (fileEntry) { fileEntry.createWriter($scope.fileWriterReceived, errorHandler); } $scope.fileWriterReceived = function (fileWriter) { var listeSouvenirsText = angular.toJson($scope.listeSouvenirs); fileWriter.write(listeSouvenirsText); } $scope.errorHandler = function (error) { console.log(error); } }]); myApp.factory("FileSystem", ["$q", function($q){ return { getFileSystem: function(){ let deferred = $q.defer(); //window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; /* var requestedBytes = 1024*1024*10; // 10MB navigator.webkitPersistentStorage.requestQuota ( requestedBytes, function (grantedBytes) { window.requestFileSystem(PERSISTENT, grantedBytes, $scope.fileSystemReceived, $scope.errorHandler); }, $scope.errorHandler ); */ window.requestFileSystem(window.PERSISTENT, 0, function(filesystem){ deferred.resolve(filesystem); }, function(error){ deferred.reject(error); }); return deferred.promise; } }; }]); function errorHandler(error) { console.log(error); } function fileSystemReceived(fileSystem) { fileSystem.root.getFile("souvenirs.json", { create: true, exclusive: false }, $scope.fileEntryReceived, $scope.errorHandler); } ons.ready(function() { //console.log("Onsen UI is ready!"); //window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; }); </script> </head> <body> <ons-splitter ng-controller="AppController as app" var="splitter"> <ons-splitter-side side="left" width="220px" collapse swipeable> <ons-page> <ons-list> <ons-list-item ng-click="app.load('home.html')" tappable> Home </ons-list-item> <ons-list-item ng-click="app.load('settings.html')" tappable> Settings </ons-list-item> <ons-list-item ng-click="app.load('about.html')" tappable> About </ons-list-item> </ons-list> </ons-page> </ons-splitter-side> <ons-splitter-content page="home.html"></ons-splitter-content> </ons-splitter> <ons-template id="home.html"> <ons-page> <ons-toolbar> <div class="left"> <ons-toolbar-button ng-click="app.toggle()"> <ons-icon icon="md-menu"></ons-icon> </ons-toolbar-button> </div> <div class="center"> Main </div> </ons-toolbar> <p style="text-align: center; opacity: 0.6; padding-top: 20px;"> Swipe right to open the menu! </p> </ons-page> </ons-template> <ons-template id="settings.html"> <ons-page> <ons-toolbar> <div class="left"> <ons-toolbar-button ng-click="app.toggle()"> <ons-icon icon="md-menu"></ons-icon> </ons-toolbar-button> </div> <div class="center"> Settings </div> </ons-toolbar> </ons-page> </ons-template> <ons-template id="about.html"> <ons-page> <ons-toolbar> <div class="left"> <ons-toolbar-button ng-click="app.toggle()"> <ons-icon icon="md-menu"></ons-icon> </ons-toolbar-button> </div> <div class="center"> About </div> </ons-toolbar> </ons-page> </ons-template> <ons-template ng-controller="SampleController"> <ons-page> <ons-toolbar> <div class="center">Test</div> </ons-toolbar> <h1>てすと</h1> <span>{{ROOT_PATH}}</span> </ons-page> </ons-template> </body> </html>
###補足情報(言語/FW/ツール等のバージョンなど)
実行環境はandroidです。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。