2012-02-08 2 views
0

OncompletionListener()를 사용하지 않고 오디오 파일을 차례대로 재생하는 방법;) 여기OnCompletionListener()를 사용하지 않고 오디오 파일을 동적으로 재생하는 방법

mp.setOnCompletionListener(new OnCompletionListener() { 

      @Override 
      public void onCompletion(MediaPlayer mp) { 
       // TODO Auto-generated method stub 
       i = i + 1; 
       System.out.println("" + audio.length); 
       if(i < audio.length){ 
        img.setImageResource(image[i]); 
        try { 
         descriptor = getAssets().openFd(audio[i]); 
         mp.reset(); 
         mp.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),descriptor.getLength()); 
         descriptor.close(); 
         mp.prepare(); 
         mp.start(); 
         xml(); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 

       } 

메소드 XML (내가 자산 폴더에서

을 따기하고 이미지 및 오디오 파일을 포함하고 또한 동적으로

을 해당 파일을 재생해야합니다 여기

내 코드입니다

도와주세요

+0

편집? – iSun

+0

죄송합니다. 다시 오지 말아주세요. – Goofy

+1

실례 합니다만, 무슨 뜻입니까? – iSun

답변

0

이 서비스는 원시에서 오디오 파일을로드합니다.이 서비스를 시작하려면 활동에 startService() (으)로 전화해야합니다. e,이 서비스를 안드로이드 매니페스트에 추가하는 것을 잊지 마십시오. 당신이 서비스 클래스를 사용하지 않는 이유는 무엇

public class Backgroundmusic extends Service { 
    // Binder given to clients 
    private final IBinder mBinder = new LocalBinder(); 
    // Random number generator 
    private final Random mGenerator = new Random(); 

    private SoundPool soundPool; 
    private HashMap<Integer, Integer> soundsMap; 
    int SOUND1=1; 
    int SOUND2=2; 
@Override 
public void onCreate() { 
    // TODO Auto-generated method stub 
    super.onCreate(); 

    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); 
    soundsMap = new HashMap<Integer, Integer>(); 
    soundsMap.put(SOUND1, soundPool.load(this, R.raw.baby_laugh, 1)); 
    soundsMap.put(SOUND2, soundPool.load(this, R.raw.touchdown, 1)); 
} 
public void playSound(int sound, float fSpeed) { 
    AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
    float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); 
    float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 
    float volume = streamVolumeCurrent/streamVolumeMax; 


    soundPool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed); 
    } 


/** 
* Class used for the client Binder. Because we know this service always 
* runs in the same process as its clients, we don't need to deal with IPC. 
*/ 
public class LocalBinder extends Binder { 
    LocalService getService() { 
     // Return this instance of LocalService so clients can call public methods 
     return LocalService.this; 
    } 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return mBinder; 
} 

/** method for clients */ 
public int getRandomNumber() { 
    return mGenerator.nextInt(100); 
} 

public void soundPlay(int index){ 

    playSound(index, 1.0f); 
    Log.d("SOUND1","hi1"); 

} } 
+0

에 도움이 될 것이라는 예를 들어주세요.하지만 여기서는 하나의 파일이 반복되지만, 여러 오디오 파일이 하나씩 재생되어야합니다. – Goofy

+0

제발 편집하십시오. – iSun

관련 문제