Multi PlayMixer : MediaPlayer « Media « Android






Multi PlayMixer

    
//package com.akjava.lib.android.sound;

import java.util.ArrayList;

import android.content.Context;
import android.media.MediaPlayer;
import android.util.Log;

public class MultiPlayMixer {
ArrayList<Player> players=new ArrayList<Player>();
  public class Player{
    public Player(Context context,int resourceId){
      mediaPlayer=MediaPlayer.create(context, resourceId);
      /*
      mediaPlayer.setOnCompletionListener(new OnCompletionListener(){
        public void onCompletion(MediaPlayer mp) {
          //???parepare??????????
          playing=false;
        }});*/
      
    }
    public boolean reservPlay;
    public boolean playing;  //TODO media ?playing????????????
    public MediaPlayer mediaPlayer;
  }
  
  public void update(){
    for (int i = 0; i <players.size(); i++) {
      if(players.get(i).reservPlay && !players.get(i).mediaPlayer.isPlaying()){
        //players.get(i).playing=true;
        players.get(i).reservPlay=false;
        players.get(i).mediaPlayer.start();
        Log.i("myapp", "play");
        
      }
    }
  }
  public int countPlayer(){
    return players.size();
  }
  public void reservePlay(int index){
    players.get(index).reservPlay=true;
  }
  
  public void finishPlay(int index){
    players.get(index).playing=false;
  }
  public Player getPlayer(int index){
    return players.get(index);
  }
  
  public void addSound(Context context,int resourceId){
    Player player=new Player(context,resourceId);
    
    players.add(player);
  }
}

   
    
    
    
  








Related examples in the same category

1.Using MediaPlayer to play MP3 file
2.MediaPlayer and Text to Speech
3.Load mp3 file with MediaPlayer and play
4.Call prepare for MediaPlayer before starting
5.Set URL data source for MediaPlayer
6.Audio MediaPlayer Demo
7.Using MediaPlayer to play Video and Audio
8.extends MediaPlayer
9.MediaPlayer create and start
10.Play movie.m4v file
11.Using Service to play media file