我創建了簡單的音頻apk。在這個apk中,我在這個選項中添加了一個名爲「選擇圖像」的選項,用於播放按鈕。我有一個問題,從圖庫中選擇的圖像沒有顯示在播放按鈕中。我已經嘗試了這個來自phonegap文檔的代碼。但它不適合我。以下是供您參考的代碼,其中我選擇了這些圖像。Phonegap從圖庫中獲取照片不起作用
我可以知道如何解決這個問題。這對我很有幫助。
<input id="mainplay" data-button="play" type="image" src="img/newplay.png" class="audiodata" id="imgData" alt="Submit" width="70" height="70" />
</div>
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
localStorage.setItem("imgData", imageURI);
$('#imgData').attr('src', imageURI);
largeImage.src ="data:image/jpeg;base64," + imageURI;
}
<div data-role="page" id="home">
<div class="ui-btn-right">
<a class="alignment ui-btn-active ui-state-persist" data-role="button" data-icon="gear" data-iconpos="notext"></a>
</div>
<div id="settings" style="display:none;">
<a href="#home" data-inline="true" data-icon="back" data-role="button" class="settings alignment" data-theme="e" data-iconpos="notext">Back</a><br><br>
<fieldset class="ui-field-contain">
<label for="Choose Audio">Choose Audio</label>
<select class="audioselect" name="selectaudio" id="selectaudio">
<option value="/android_asset/www/audio/Commercial DEMO - 15.mp3">Commercial DEMO</option><option value="/android_asset/www/audio/p1rj1s_-_rockGuitar.mp3">RockGuitar</option>
</select>
</fieldset><br>
<fieldset class="ui-field-contain">
<label for="Volume">Volume Control</label><br>
<span class="tooltip"></span> <!-- Tooltip -->
<div id="slider"></div> <!-- the Slider -->
<span class="volume"></span> <!-- Volume -->
</fieldset><br>
<fieldset>
<button data-inline="true" onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">Choose Photos</button>
<div style="display:none;"><img id="largeImage" src="" /></div> </fieldset><br>
</div>
<input id="mainplay" data-button="play" type="image" src="img/newplay.png" class="audiodata" id="imgData" alt="Submit" width="70" height="70" />
</div>
您使用的是什麼版本的cordova?任何控制檯錯誤?.. – Aravin 2014-09-30 08:00:22
科爾多瓦3.5.1版本 – Sri 2014-09-30 11:27:44
是你添加了需求插件.. – Aravin 2014-09-30 13:27:04