Here is an example code for android
var Activity = require('android.app.Activity');
var AudioManager = require('android.media.AudioManager');
var MediaPlayer = require('android.media.MediaPlayer');
var Uri = require('android.net.Uri');
var activity = new Activity(Ti.Android.currentActivity);
var context = activity.getApplicationContext();
var mMediaPlayer;
var contentUri = Uri.parse('android.resource://' + activity.getPackageName() + '/raw/abc');
//var myUri = Uri.parse("app/platform/android/res/raw/five.mp3");
//Ti.API.info("myUri=" + myUri);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener({
onCompletion : function(mediaPlayer) {
Ti.API.info('MediaPlayer playback completed');
}
}));
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(context, contentUri);
mMediaPlayer.prepare();
function startMedia() {
mMediaPlayer.start();
}
function stopMedia() {
mMediaPlayer.pause();
// NOTE: You can also stop it, but then you have to prepare() it again as well
// mMediaPlayer.stop();
// mMediaPlayer.prepare();
}
$.win1.open();
Git link: https://github.com/appcelerator/hyperloop-examples/commit/d983520db7f10d2ad5209fce09b9f560621aa1f3
For Video file: https://github.com/appcelerator/hyperloop-examples/blob/master/app/controllers/android/videoplayer.js
Hope this helps.
Brilliant - very helpful.
ReplyDelete