You are never going to sync perfectly doing it this way. You have to mix the sound data together yourself and then feed it out as one PCM stream
On Saturday, March 9, 2013 12:25:51 PM UTC-6, Dharmendra Deshmukh wrote: > > This is Application Code I am Posting here.. > > > > > > public class MulitrackmixtureActivity extends Activity { > /** Called when the activity is first created. */ > public Button play, pause, rew; > public MediaPlayer mediaPlayer, mediaPlayer2, mediaPlayer3, mediaPlayer4, > mediaPlayer5, mediaPlayer6; > SeekBar seek, trk1vol, trk2vol, trk3vol, trk4vol, trk5vol, trk6vol; > AudioManager audioManager; > private final Handler handler = new Handler(); > > public static final int S1 = R.raw.track1a; > public static final int S2 = R.raw.track2a; > public static final int S3 = R.raw.track3a; > public static final int S4 = R.raw.track4a; > public static final int S5 = R.raw.track5a; > public static final int S6 = R.raw.track6a; > > > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > seek = (SeekBar) findViewById(R.id.seekBar1); > play = (Button) findViewById(R.id.play_btn); > pause = (Button) findViewById(R.id.pause_btn); > rew = (Button) findViewById(R.id.rew_btn); > > mediaPlayer = new MediaPlayer(); > mediaPlayer = MediaPlayer.create(this, S1); > > mediaPlayer2 = new MediaPlayer(); > mediaPlayer2 = MediaPlayer.create(this, S2); > > mediaPlayer3 = new MediaPlayer(); > mediaPlayer3 = MediaPlayer.create(this, S3); > > mediaPlayer4 = new MediaPlayer(); > mediaPlayer4 = MediaPlayer.create(this, S4); > > mediaPlayer5 = new MediaPlayer(); > mediaPlayer5 = MediaPlayer.create(this, S5); > > mediaPlayer6 = new MediaPlayer(); > mediaPlayer6 = MediaPlayer.create(this, S6); > > audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); > > int maxVolume = audioManager > .getStreamMaxVolume(AudioManager.STREAM_MUSIC); > int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); > > trk1vol = (SeekBar) findViewById(R.id.seekBar2); > trk2vol = (SeekBar) findViewById(R.id.seekBar3); > trk3vol = (SeekBar) findViewById(R.id.seekBar4); > trk4vol = (SeekBar) findViewById(R.id.seekBar5); > trk5vol = (SeekBar) findViewById(R.id.seekBar6); > trk6vol = (SeekBar) findViewById(R.id.seekBar7); > > trk1vol.setMax(maxVolume); > trk2vol.setMax(maxVolume); > trk3vol.setMax(maxVolume); > trk4vol.setMax(maxVolume); > trk5vol.setMax(maxVolume); > trk6vol.setMax(maxVolume); > > trk1vol.setProgress(curVolume); > trk2vol.setProgress(curVolume); > trk3vol.setProgress(curVolume); > trk4vol.setProgress(curVolume); > trk5vol.setProgress(curVolume); > trk6vol.setProgress(curVolume); > > trk1vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk1vol)) { > > mediaPlayer.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > trk2vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk2vol)) { > > mediaPlayer2.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > trk3vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk3vol)) { > > mediaPlayer3.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > trk4vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk4vol)) { > > mediaPlayer4.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > trk5vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk5vol)) { > > mediaPlayer5.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > trk6vol.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { > > public void onStopTrackingTouch(SeekBar seekBar) { > > } > > public void onStartTrackingTouch(SeekBar arg0) { > > } > > public void onProgressChanged(SeekBar seekBar, int progress, > boolean arg2) { > try { > if (seekBar.equals(trk6vol)) { > > mediaPlayer6.setVolume((progress / 10.0f), > (progress / 10.0f)); > } > } catch (Exception e) { > // TODO: handle exception > } > } > }); > > seek.setMax(mediaPlayer.getDuration()); > > seek.setOnTouchListener(new OnTouchListener() { > public boolean onTouch(View v, MotionEvent event) { > seekChange(v); > return false; > } > }); > > play.setOnClickListener(new View.OnClickListener() { > > public void onClick(View arg0) { > // check for already playing > try { > > if (mediaPlayer.isPlaying() > || mediaPlayer2.isPlaying() > || mediaPlayer3.isPlaying() > || mediaPlayer4.isPlaying() > || mediaPlayer5.isPlaying() > || mediaPlayer6.isPlaying()) { > if (mediaPlayer != null > && mediaPlayer2 != null > && mediaPlayer3 != null > && mediaPlayer4 != null > && mediaPlayer5 != null > && mediaPlayer6 != null) { > int position = mediaPlayer.getCurrentPosition(); > int position2 = mediaPlayer2.getCurrentPosition(); > int position3 = mediaPlayer3.getCurrentPosition(); > int position4 = mediaPlayer4.getCurrentPosition(); > int position5 = mediaPlayer5.getCurrentPosition(); > int position6 = mediaPlayer6.getCurrentPosition(); > mediaPlayer.pause(); > mediaPlayer.seekTo(position); > mediaPlayer2.pause(); > mediaPlayer2.seekTo(position2); > mediaPlayer3.pause(); > mediaPlayer3.seekTo(position3); > mediaPlayer4.pause(); > mediaPlayer4.seekTo(position4); > mediaPlayer5.pause(); > mediaPlayer5.seekTo(position5); > mediaPlayer6.pause(); > mediaPlayer6.seekTo(position6); > > } > } else { > // Resume song > // if (mediaPlayer != null > // && mediaPlayer2 != null > // && mediaPlayer3 != null > // && mediaPlayer4 != null > // && mediaPlayer5 != null > // && mediaPlayer6 != null) { > mediaPlayer.start(); > mediaPlayer2.start(); > mediaPlayer3.start(); > mediaPlayer4.start(); > mediaPlayer5.start(); > mediaPlayer6.start(); > > // Changing button image to pause button > > startPlayProgressUpdater(); > // } > > } > > } catch (Exception e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > }); > > } > > public void startPlayProgressUpdater() { > seek.setProgress(mediaPlayer.getCurrentPosition()); > > if (mediaPlayer.isPlaying() > || mediaPlayer2.isPlaying() > || mediaPlayer3.isPlaying() > || mediaPlayer4.isPlaying() > || mediaPlayer5.isPlaying() > || mediaPlayer6.isPlaying()) { > Runnable notification = new Runnable() { > public void run() { > startPlayProgressUpdater(); > } > }; > handler.postDelayed(notification, 50); > } else { > mediaPlayer.pause(); > mediaPlayer2.pause(); > mediaPlayer3.pause(); > mediaPlayer4.pause(); > mediaPlayer5.pause(); > mediaPlayer6.pause(); > > seek.setProgress(mediaPlayer.getCurrentPosition()); > } > } > > private void seekChange(View v) { > if (mediaPlayer.isPlaying() || mediaPlayer2.isPlaying() > || mediaPlayer3.isPlaying() || mediaPlayer4.isPlaying() > || mediaPlayer5.isPlaying() || mediaPlayer6.isPlaying()) { > // SeekBar sb = (SeekBar) v; > mediaPlayer.seekTo(seek.getProgress()); > mediaPlayer2.seekTo(seek.getProgress()); > mediaPlayer3.seekTo(seek.getProgress()); > mediaPlayer4.seekTo(seek.getProgress()); > mediaPlayer5.seekTo(seek.getProgress()); > mediaPlayer6.seekTo(seek.getProgress()); > } > } > > public void onBackPressed() { > try { > System.exit(1); > > mediaPlayer.release(); > mediaPlayer2.release(); > mediaPlayer3.release(); > mediaPlayer4.release(); > mediaPlayer5.release(); > mediaPlayer6.release(); > > } catch (Exception e) { > e.printStackTrace(); > } > super.onBackPressed(); > } > } > > > > > > > > problume on Application---- > > > > > this an music mixture > > i will 12 trracks to be play > > right now i have 6tracks ke saath. > > They are working .but problume is when i click play button all media track > play different miliseconds. > > If i drag seek bar then difference will be end but i pause and then play > again same problume > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.