我创建了简单的音频apk。在这个apk中,我在此选项中为“播放”按钮添加了一个名为“选择图像”的选项。我有一个问题,即从“画廊”中选择的图像未显示在“播放”按钮中。我试过这个来自phonegap doc的代码。但它不适合我。以下是供您参考的代码,其中我选择了图像。
我可以知道如何解决这个问题。这对我很有帮助。
<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>
答案 0 :(得分:0)
您需要一个ondeviceready函数并添加这两行代码;
pictureSource = navigator.camera.PictureSourceType; destinationType = navigator.camera.DestinationType;
请继续阅读here并仔细研究完整的例子。