Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abe48e2
commit d983520
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
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; | ||
|
||
(function(container) { | ||
var contentUri = Uri.parse('android.resource://' + activity.getPackageName() + '/raw/audio'); | ||
|
||
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(); | ||
})($.window); | ||
|
||
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(); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Alloy> | ||
<Window id="win" title="Media Player"> | ||
<Button top="100" title="Start Media" onClick="startMedia" /> | ||
<Button top="200" title="Stop Media" onClick="stopMedia" /> | ||
</Window> | ||
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters