<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>Sample</title>
<script src="cordova-2.7.0.js" type="text/javascript"></script>
<script src="tts.js" type="text/javascript"></script>
<script type="text/javascript">
if (!navigator.userAgent.toLowerCase().match('chrome')) {
document.write("<script src='phonegap.js'></script>");
}
</script>
</head>
<body onload="onLoaded()">
<h1>Example</h1>
<p>Read File</p>
<div id="info" style="font-size:12px"></div>
<script>

// Wait for Cordova to load
//
function onLoaded() {
alert('onLoad');
document.addEventListener("deviceready", onDeviceReady, false);
}

// Cordova is ready
//
function onDeviceReady() {
alert('onDeviceReady');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
alert('gotFS');
fileSystem.root.getFile("TTS1.txt", null, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
alert('gotFileEntry');
fileEntry.file(gotFile, fail);
}

function gotFile(file){
alert('gotFile');
readDataUrl(file);
readAsText(file);
}

function readDataUrl(file) {
alert('readDataUrl');
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}

function readAsText(file) {
alert('readAsText');
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
document.getElementById("info").innerHTML=evt.target.result;
};
reader.readAsText(file);
}

function fail(evt) {
alert('fail');
console.log(evt.target.error.code);
}

</script>
</body>
</html>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 amychang2014 的頭像
    amychang2014

    工作需要筆記

    amychang2014 發表在 痞客邦 留言(0) 人氣()