Skip to content

Instantly share code, notes, and snippets.

@csik
Created August 23, 2013 09:15
Show Gist options
  • Save csik/6317208 to your computer and use it in GitHub Desktop.
Save csik/6317208 to your computer and use it in GitHub Desktop.
Android audio mixing using Pyjnius [http://pyjnius.readthedocs.org/en/latest/android.html].
from jnius import autoclass
from time import sleep
MediaPlayer = autoclass('android.media.MediaPlayer')
ones = MediaPlayer()
ones.setDataSource("/sdcard/Music/05 Steve Miller Band Fly Like An Eagle Remix.mp3")
ones.prepare()
twos = MediaPlayer()
twos.setDataSource("/sdcard/Music/04 Jay Z Empire State Of Mind Remix.mp3")
twos.prepare()
print 'duration:', ones.getDuration()
ones.start()
twos.start()
while ones.isPlaying() or twos.isPlaying():
for vol in range(0,100):
ones.setVolume(vol/100.0,vol/100.0)
twos.setVolume(1-vol/100.0,1-vol/100.0)
print 'current position:', ones.getCurrentPosition()
sleep(.1)
for vol in range(100,0,-1):
ones.setVolume(vol/100.0,vol/100.0)
twos.setVolume(1-vol/100.0,1-vol/100.0)
print 'current position:', ones.getCurrentPosition()
sleep(.1)
ones.release()
twos.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment