牙叔教程 简单易懂
第一种: webview播放
"ui";
ui.layout(
<vertical>
<webview id="webview" h="*" />
</vertical>
);
let url = "https://api.vvhan.com/api/rand.music?sort=新歌榜";
ui.webview.loadUrl(url);
第二种: 拦截跳转, 下载歌曲播放
http.__okhttp__.muteClient(Packages.okhttp3.OkHttpClient.Builder().followRedirects(false));
let url = "https://api.vvhan.com/api/rand.music?sort=新歌榜";
let r = http.get(url);
// log(r.body);
// { response:
// { raw: Response{protocol=http/1.1, code=302, message=Found, url=https://api.vvhan.com/api/rand.music?sort=%E6%96%B0%E6%AD%8C%E6%A6%9C},
// statusCode: 302,
// statusMessage: 'Found',
// body: [Circular],
// request: Request{method=GET, url=https://api.vvhan.com/api/rand.music?sort=%E6%96%B0%E6%AD%8C%E6%A6%9C, tags={}},
// url: https://api.vvhan.com/api/rand.music?sort=%E6%96%B0%E6%AD%8C%E6%A6%9C,
// method: 'GET',
// headers:
// { Server: 'CWAP-waf',
// Date: 'Sun, 14 Aug 2022 02:28:23 GMT',
// 'Content-Type': 'text/html; charset=UTF-8',
// 'Transfer-Encoding': 'chunked',
// Connection: 'keep-alive',
// 'Access-Control-Allow-Origin': '*',
// Location: 'https://m701.music.126.net/20220814105323/bcd5d26f69170e1e0782b77bf72aa8ec/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/16629720829/169a/f8ba/a11c/944fab1fa5bb538f0e4e32f5a7783f76.mp3',
// 'Strict-Transport-Security': 'max-age=31536000',
// 'WZWS-RAY': '1139-1660472903.367-s2jhg',
// 'X-Powered-By': 'wangzhan.qianxin.com' } },
// raw: okhttp3.internal.http.RealResponseBody@3887583,
// contentType: text/html; charset=UTF-8 }
let Location = r.body.response.headers.Location;
r = http.get(Location);
let filePath = "/sdcard/脚本/Download/music.mp3";
files.createWithDirs(filePath);
files.writeBytes(filePath, r.body.bytes());
media.playMusic(filePath);
setInterval(() => {}, 1000);
环境
手机:小米11pro
MIUI: 13.0.12
Android版本: 12
Autojs版本: 9.2.5
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问 --- 牙叔教程
声明
部分内容来自网络 本教程仅用于学习, 禁止用于其他用途