Merge pull request #752 from minggo/iss721_cocosdenshion

fixed #721: cocosdenshion can play local  file on android
This commit is contained in:
minggo 2012-03-06 00:58:51 -08:00
commit 837da31d59
6 changed files with 51 additions and 21 deletions

View File

@ -203,14 +203,18 @@ public class Cocos2dxMusic {
* @return
*/
private MediaPlayer createMediaplayerFromAssets(String path){
MediaPlayer mediaPlayer = null;
MediaPlayer mediaPlayer = new MediaPlayer();
try{
if (path.startsWith("/")) {
mediaPlayer.setDataSource(path);
}
else {
AssetFileDescriptor assetFileDescritor = mContext.getAssets().openFd(path);
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(),
assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
}
mediaPlayer.prepare();
mediaPlayer.setVolume(mLeftVolume, mRightVolume);

View File

@ -219,8 +219,14 @@ public class Cocos2dxSound {
int soundId = INVALID_SOUND_ID;
try {
if (path.startsWith("/")){
soundId = mSoundPool.load(path, 0);
}
else {
soundId = mSoundPool.load(mContext.getAssets().openFd(path), 0);
}
} catch(Exception e){
soundId = INVALID_SOUND_ID;
Log.e(TAG, "error: " + e.getMessage(), e);
}

View File

@ -203,14 +203,18 @@ public class Cocos2dxMusic {
* @return
*/
private MediaPlayer createMediaplayerFromAssets(String path){
MediaPlayer mediaPlayer = null;
MediaPlayer mediaPlayer = new MediaPlayer();
try{
if (path.startsWith("/")) {
mediaPlayer.setDataSource(path);
}
else {
AssetFileDescriptor assetFileDescritor = mContext.getAssets().openFd(path);
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(),
assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
}
mediaPlayer.prepare();
mediaPlayer.setVolume(mLeftVolume, mRightVolume);

View File

@ -219,8 +219,14 @@ public class Cocos2dxSound {
int soundId = INVALID_SOUND_ID;
try {
if (path.startsWith("/")){
soundId = mSoundPool.load(path, 0);
}
else {
soundId = mSoundPool.load(mContext.getAssets().openFd(path), 0);
}
} catch(Exception e){
soundId = INVALID_SOUND_ID;
Log.e(TAG, "error: " + e.getMessage(), e);
}

View File

@ -203,14 +203,18 @@ public class Cocos2dxMusic {
* @return
*/
private MediaPlayer createMediaplayerFromAssets(String path){
MediaPlayer mediaPlayer = null;
MediaPlayer mediaPlayer = new MediaPlayer();
try{
if (path.startsWith("/")) {
mediaPlayer.setDataSource(path);
}
else {
AssetFileDescriptor assetFileDescritor = mContext.getAssets().openFd(path);
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(),
assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
}
mediaPlayer.prepare();
mediaPlayer.setVolume(mLeftVolume, mRightVolume);

View File

@ -219,8 +219,14 @@ public class Cocos2dxSound {
int soundId = INVALID_SOUND_ID;
try {
if (path.startsWith("/")){
soundId = mSoundPool.load(path, 0);
}
else {
soundId = mSoundPool.load(mContext.getAssets().openFd(path), 0);
}
} catch(Exception e){
soundId = INVALID_SOUND_ID;
Log.e(TAG, "error: " + e.getMessage(), e);
}