use of org.awesomeapp.messenger.util.HttpMediaStreamer in project Zom-Android by zom.
the class AudioWife method initPlayer.
/**
**
* Initialize and prepare the audio player
***
*/
private void initPlayer(Context ctx, final Uri mediaUri, String mimeType) throws IOException {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (mediaUri.getScheme() != null) {
if (mediaUri.getScheme().equals("vfs")) {
final info.guardianproject.iocipher.File fileMediaEncrypted = new info.guardianproject.iocipher.File(mediaUri.getPath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mMediaPlayer.setDataSource(new MediaDataSource() {
final info.guardianproject.iocipher.RandomAccessFile fis = new info.guardianproject.iocipher.RandomAccessFile(fileMediaEncrypted, "r");
@Override
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
if (position > getSize())
return -1;
fis.seek(position);
byte[] outBuffer = new byte[size];
int readSize = fis.read(outBuffer, 0, size);
System.arraycopy(outBuffer, 0, buffer, offset, size);
return readSize;
}
@Override
public long getSize() throws IOException {
return fis.length();
}
@Override
public void close() throws IOException {
if (fis != null)
fis.close();
}
});
} else {
HttpMediaStreamer streamer = new HttpMediaStreamer(fileMediaEncrypted, mimeType);
Uri uri = streamer.getUri();
mMediaPlayer.setDataSource(ctx, uri);
}
} else if (mediaUri.getScheme().equals("content")) {
mMediaPlayer.setDataSource(ctx, mediaUri);
} else if (mediaUri.getScheme().equals("file")) {
mMediaPlayer.setDataSource(ctx, mediaUri);
}
} else {
mMediaPlayer.setDataSource(mediaUri.getPath());
}
try {
mMediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
mMediaPlayer.setOnCompletionListener(mOnCompletion);
}
use of org.awesomeapp.messenger.util.HttpMediaStreamer in project Zom-Android by zom.
the class AudioPlayer method initPlayer.
public void initPlayer() throws Exception {
final File fileStream = new File(mFileName);
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying())
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (fileStream.exists()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.setDataSource(new MediaDataSource() {
info.guardianproject.iocipher.RandomAccessFile fis;
@Override
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
if (fis == null)
fis = new info.guardianproject.iocipher.RandomAccessFile(fileStream, "r");
if (position > getSize())
return -1;
fis.seek(position);
byte[] outBuffer = new byte[size];
int readSize = fis.read(outBuffer, 0, size);
System.arraycopy(outBuffer, 0, buffer, offset, size);
return readSize;
}
@Override
public long getSize() throws IOException {
return fileStream.length();
}
@Override
public void close() throws IOException {
if (fis != null)
fis.close();
}
});
} else {
streamer = new HttpMediaStreamer(fileStream, mMimeType);
Uri uri = streamer.getUri();
mediaPlayer.setDataSource(mContext, uri);
}
} else {
mediaPlayer.setDataSource(mFileName);
}
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
Log.d("AudioPlayer", "there was an error loading music: " + i + " " + i1);
return true;
}
});
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mPrepared = true;
mDuration = mediaPlayer.getDuration();
mInfoView.setText((getDuration() / 1000) + "secs");
if (mPlayOnPrepare)
play();
}
});
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mVisualizer != null)
mVisualizer.setEnabled(false);
}
});
// mediaPlayer.prepareAsync();
}
Aggregations