如何玩歌的Andr​​oid - PhoneGap的 [英] How to play song in Android - phonegap

查看:101
本文介绍了如何玩歌的Andr​​oid - PhoneGap的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个月前,我开始用的PhoneGap,HTML5,CSS3和jQtouch工作。 我工作的一个应用程序,我需要在应用程序中播放声音。我有这个任务的一个严重问题。 首先,我发现我可以使用新媒体(...)函数通过PhoneGap的播放.mp3文件。我不知道.wav文件,我可以玩那些? 其次我发现,文件必须小于30秒,是这样吗? 第三,我不能找到合适的地方,我的声音文件。我的项目结构如下:

A month ago I started working with phonegap, html5, css3 and jQtouch. I am working on an application and I need to play sound in the application. I have a serious problem with this task. First I've found out that I can play .mp3 files through phonegap using the new Media(...) function. I am not sure about .wav files, can I play those? Second I've found that files must be less than 30 sec, is this so? Third I can't find the right place for my sound files. My project structure is the following:

project
-- src
-- gen
-- assets
-- -- www
-- -- DANCE.mp3
-- -- jqtouch
-- -- -- (some folders and files)
-- -- phonegap.js
-- libs
-- res

我已经试过将在WWW文件夹中的文件并创建一个新的名为音频。这一切都不给我我想要的东西。 我用这$ C $下执行歌曲:

I've tried placing the file in 'www' folder and creating a new one called 'audio'. None of this gave me what I wanted. I am using this code for executing the song:

function playStream() {
    mp3file = new Media("DANCE.mp3",
            function() {
                alert("playAudio():Audio Success");
            },
                function(err) {
                    alert(err);
            }
            );
          mp3file.play();
}

我采用Android 2.1模拟器,我已经试过2.2也没有成功。 我希望我是清楚。 我期待着您的回音。 此致, 米哈伊尔者velikov

I use Android 2.1 Simulator and I've tried 2.2 as well without success. I hope I was clear enough. I am looking forward to hearing from you. Yours, Mihail Velikov

推荐答案

的PhoneGap为Android可以让您保存在两个地方的本地音频文件:  android_asset:文件名必须以/android_asset/sound.mp3  SD卡:文件名是刚sound.mp3

PhoneGap for Android lets you store local audio files in two places: android_asset: file name must start with /android_asset/sound.mp3 sdcard: file name is just sound.mp3

如果你把你的DANCE.mp3文件在项目的资产目录,则可以使用路径播放:

If you place your DANCE.mp3 file in your project's assets directory, then you can play it using the path:

mp3file = new Media("/android_asset/DANCE.mp3",
        function() {
            alert("playAudio():Audio Success");
        },
            function(err) {
                alert(err);
        }
        );
      mp3file.play();

(你可以阅读在Android PhoneGap的源源AudioPlayer.java,看看它是如何工作。)

(You can read the source for AudioPlayer.java in the Android PhoneGap sources to see how this works.)

这篇关于如何玩歌的Andr​​oid - PhoneGap的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆