api: add module media
This commit is contained in:
@@ -80,7 +80,7 @@ require("__globals__")(__runtime__, this);
|
|||||||
(function(scope){
|
(function(scope){
|
||||||
var modules = ['app', 'automator', 'console', 'dialogs', 'io', 'selector', 'shell', 'web', 'ui',
|
var modules = ['app', 'automator', 'console', 'dialogs', 'io', 'selector', 'shell', 'web', 'ui',
|
||||||
"images", "timers", "threads", "events", "engines", "RootAutomator", "http", "storages", "floaty",
|
"images", "timers", "threads", "events", "engines", "RootAutomator", "http", "storages", "floaty",
|
||||||
"sensors"];
|
"sensors", "media"];
|
||||||
var len = modules.length;
|
var len = modules.length;
|
||||||
for(var i = 0; i < len; i++) {
|
for(var i = 0; i < len; i++) {
|
||||||
var m = modules[i];
|
var m = modules[i];
|
||||||
|
|||||||
3
autojs/src/main/assets/modules/__media__.js
Normal file
3
autojs/src/main/assets/modules/__media__.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function(runtime, global){
|
||||||
|
return Object.create(runtime.media);
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import com.stardust.autojs.runtime.api.Events;
|
|||||||
import com.stardust.autojs.runtime.api.Files;
|
import com.stardust.autojs.runtime.api.Files;
|
||||||
import com.stardust.autojs.runtime.api.Floaty;
|
import com.stardust.autojs.runtime.api.Floaty;
|
||||||
import com.stardust.autojs.core.looper.Loopers;
|
import com.stardust.autojs.core.looper.Loopers;
|
||||||
|
import com.stardust.autojs.runtime.api.Media;
|
||||||
import com.stardust.autojs.runtime.api.Sensors;
|
import com.stardust.autojs.runtime.api.Sensors;
|
||||||
import com.stardust.autojs.runtime.api.Threads;
|
import com.stardust.autojs.runtime.api.Threads;
|
||||||
import com.stardust.autojs.runtime.api.Timers;
|
import com.stardust.autojs.runtime.api.Timers;
|
||||||
@@ -175,6 +176,8 @@ public class ScriptRuntime {
|
|||||||
@ScriptVariable
|
@ScriptVariable
|
||||||
public Sensors sensors;
|
public Sensors sensors;
|
||||||
|
|
||||||
|
@ScriptVariable
|
||||||
|
public final Media media;
|
||||||
|
|
||||||
private Images images;
|
private Images images;
|
||||||
|
|
||||||
@@ -205,6 +208,7 @@ public class ScriptRuntime {
|
|||||||
device = new Device(context);
|
device = new Device(context);
|
||||||
floaty = new Floaty(uiHandler, ui, this);
|
floaty = new Floaty(uiHandler, ui, this);
|
||||||
files = new Files(this);
|
files = new Files(this);
|
||||||
|
media = new Media(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -366,6 +370,7 @@ public class ScriptRuntime {
|
|||||||
}
|
}
|
||||||
ignoresException(threads::shutDownAll);
|
ignoresException(threads::shutDownAll);
|
||||||
ignoresException(events::recycle);
|
ignoresException(events::recycle);
|
||||||
|
ignoresException(media::recycle);
|
||||||
ignoresException(loopers::recycle);
|
ignoresException(loopers::recycle);
|
||||||
ignoresException(() -> {
|
ignoresException(() -> {
|
||||||
if (mRootShell != null) mRootShell.exitAndWaitFor();
|
if (mRootShell != null) mRootShell.exitAndWaitFor();
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ public class Media implements MediaScannerConnection.MediaScannerConnectionClien
|
|||||||
|
|
||||||
public Media(Context context) {
|
public Media(Context context) {
|
||||||
mScannerConnection = new MediaScannerConnection(context, this);
|
mScannerConnection = new MediaScannerConnection(context, this);
|
||||||
|
mScannerConnection.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scan(String path) {
|
public void scanFile(String path) {
|
||||||
String mimeType = MimeTypes.fromFileOr(path, null);
|
String mimeType = MimeTypes.fromFileOr(path, null);
|
||||||
mScannerConnection.scanFile(path, mimeType);
|
mScannerConnection.scanFile(path, mimeType);
|
||||||
}
|
}
|
||||||
@@ -33,6 +34,14 @@ public class Media implements MediaScannerConnection.MediaScannerConnectionClien
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playMusic(String path, float volume) {
|
||||||
|
playMusic(path, volume, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playMusic(String path) {
|
||||||
|
playMusic(path, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public void playMusic(String path, float volume, boolean looping) {
|
public void playMusic(String path, float volume, boolean looping) {
|
||||||
if (mMediaPlayer == null) {
|
if (mMediaPlayer == null) {
|
||||||
mMediaPlayer = new MediaPlayerWrapper();
|
mMediaPlayer = new MediaPlayerWrapper();
|
||||||
@@ -40,11 +49,12 @@ public class Media implements MediaScannerConnection.MediaScannerConnectionClien
|
|||||||
mMediaPlayer.stopAndReset();
|
mMediaPlayer.stopAndReset();
|
||||||
try {
|
try {
|
||||||
mMediaPlayer.setDataSource(path);
|
mMediaPlayer.setDataSource(path);
|
||||||
|
mMediaPlayer.setVolume(volume, volume);
|
||||||
|
mMediaPlayer.setLooping(looping);
|
||||||
|
mMediaPlayer.prepare();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
mMediaPlayer.setVolume(volume, volume);
|
|
||||||
mMediaPlayer.setLooping(looping);
|
|
||||||
mMediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user