Commit 6cd4f115 by 黄晋宇

音乐库升级

parent 6bc29a80
......@@ -594,6 +594,7 @@ public class PolyvDownloaderManager {
/**
* 添加一个任务
* 注:同样的URL,保存的目录不一样表示这两次addTask是不同的任务
* 注:不同的URL(path相同),保存的目录一样表示这两次addTask是相同的任务
*
* @param downloaderModel
* @return
......@@ -620,6 +621,16 @@ public class PolyvDownloaderManager {
downloaderModel.setTaskId(id);
//去除添加数据库操作,等下载完成后插入数据库
// model = mDbController.addTask(downloaderModel);
for (int i = 0; i < mAllTasks.size(); i++) {
PolyvFileDownloaderModel model = mAllTasks.valueAt(i);
String urlPath = url.contains("?") ? url.substring(0, url.indexOf("?")) : url;
String modelUrlPath = model.getUrl().contains("?") ? model.getUrl().substring(0, model.getUrl().indexOf("?")) : model.getUrl();
if (model.getPath().equals(path) && modelUrlPath.equals(urlPath)) {
return model;
}
}
mAllTasks.put(id, downloaderModel);
return downloaderModel;
......
......@@ -10,6 +10,7 @@ import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
......@@ -68,6 +69,8 @@ public class PolyvPlayerListActivity extends AppCompatActivity implements View.O
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.polyv_activity_main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
PolyvDesignUtils.generateWindowWH(this);
PolyvVideoViewLayoutManager.create(getApplicationContext(), videoViewLayoutCount);
......
......@@ -66,4 +66,6 @@
-keep class com.easefun.polyvsdk.**{*;}
-keep class org.apache.http.**{*;}
-keep class tv.danmaku.ijk.media.**{*;}
\ No newline at end of file
-keep class tv.danmaku.ijk.media.**{*;}
-keep class com.polyv.shortvideo.sdk.**{*;}
......@@ -2,22 +2,17 @@ package com.polyv.apsaravideo.music.music;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.polyv.downloader.PolyvDownloaderManager;
import com.polyv.downloader.PolyvFileDownloaderCallback;
import com.polyv.downloader.PolyvFileDownloaderModel;
import com.polyv.shortvideo.sdk.PolyvAPIHelper;
import com.polyv.shortvideo.sdk.common.utils.PolyvCommonUtil;
import com.polyv.shortvideo.sdk.common.utils.PolyvStorageUtils;
import com.polyv.shortvideo.sdk.qupaiokhttp.PolyvHttpRequest;
import com.polyv.shortvideo.sdk.qupaiokhttp.PolyvStringHttpRequestCallback;
import com.polyv.video.common.utils.PolyvToastUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -25,11 +20,9 @@ import java.util.List;
public class PolyvMusicLoader {
public static final int EFFECT_MUSIC = 5; //音乐
/**
* 音螺音乐详情URL
* 音URL
*/
private static final String URL_MUSIC_DETAIL = "https://demo-vod.cn-shanghai.aliyuncs"
+ ".com/voddemo/XiamiApiMltpMusicPlayinfo?BusinessType=vodsdk&TerminalType=pc&DeviceModel=iPhone9,"
+ "2&UUID=59ECA-4193-4695-94DD-7E1247288&AppVersion=1.0.0&play_info_get={\"music_id\":\"%s\"}";
private static final String URL = "http://www.spbao.com/api/easeP/material/%s.mp3?id=%s&ptime=%s&sign=%s";
private final PolyvMusicQuery mMusicQuery;
private final Context mContext;
private LoadCallback callback;
......@@ -111,78 +104,50 @@ public class PolyvMusicLoader {
Toast.makeText(mContext, com.polyv.apsaravideo.music.R.string.polyv_no_free_memory, Toast.LENGTH_SHORT).show();
return;
}
String url = String.format(URL_MUSIC_DETAIL, musicFileBean.musicId);
PolyvHttpRequest.get(url, new PolyvStringHttpRequestCallback() {
final String time = System.currentTimeMillis() + "";
final String musicId = musicFileBean.getMusicId();
String sign = PolyvAPIHelper.getMusicSign(musicId, time);
String musicUrl = String.format(URL, musicId, musicId, time, sign);
final PolyvFileDownloaderModel downloaderModel = new PolyvFileDownloaderModel();
downloaderModel.setUrl(musicUrl);
downloaderModel.setDownload(musicFileBean.getMusicId());
downloaderModel.setName(musicFileBean.title);
downloaderModel.setIsunzip(0);
downloaderModel.setDuration(musicFileBean.duration);
downloaderModel.setPath(PolyvStorageUtils.getFilesDirectory(mContext) + "/music/" + musicFileBean.title);
downloaderModel.setDescription(musicFileBean.artist);
downloaderModel.setEffectType(EFFECT_MUSIC);
final PolyvFileDownloaderModel model = PolyvDownloaderManager.getInstance().addTask(downloaderModel, musicUrl);
if (PolyvDownloaderManager.getInstance().isDownloading(model.getTaskId(), model.getPath())) {
return;
}
PolyvDownloaderManager.getInstance().startTask(model.getTaskId(), new PolyvFileDownloaderCallback() {
@Override
public void onSuccess(String s) {
super.onSuccess(s);
try {
Log.e("TAG", s);
JSONObject jsonObject = new JSONObject(s);
String code = jsonObject.getString("code");
if ("ok".equals(code)) {
JSONObject result = jsonObject.getJSONObject("result");
String status = result.getString("status");
if ("true".equals(status)) {
String url = result.getJSONObject("result_obj").getString("listen_file_url");
final PolyvFileDownloaderModel downloaderModel = new PolyvFileDownloaderModel();
downloaderModel.setUrl(url);
downloaderModel.setDownload(musicFileBean.getMusicId());
downloaderModel.setName(musicFileBean.title);
downloaderModel.setIsunzip(0);
downloaderModel.setDuration(musicFileBean.duration);
downloaderModel.setPath(PolyvStorageUtils.getFilesDirectory(mContext) + "/music/" + musicFileBean.title);
downloaderModel.setDescription(musicFileBean.artist);
downloaderModel.setEffectType(EFFECT_MUSIC);
final PolyvFileDownloaderModel model = PolyvDownloaderManager.getInstance().addTask(downloaderModel, url);
if (PolyvDownloaderManager.getInstance().isDownloading(model.getTaskId(), model.getPath())) {
return;
}
PolyvDownloaderManager.getInstance().startTask(model.getTaskId(), new PolyvFileDownloaderCallback() {
@Override
public void onFinish(int downloadId, String path) {
callback.onFinish(downloadId, path);
}
@Override
public void onStart(int downloadId, long soFarBytes, long totalBytes, int preProgress) {
callback.onStart(downloadId, soFarBytes, totalBytes, preProgress);
}
@Override
public void onProgress(int downloadId, long soFarBytes, long totalBytes, long speed,
int progress) {
callback.onProgress(downloadId, soFarBytes, totalBytes, speed, progress);
}
@Override
public void onError(BaseDownloadTask task, Throwable e) {
PolyvToastUtils.show(mContext, com.polyv.apsaravideo.music.R.string.polyv_download_failed);
PolyvDownloaderManager.getInstance().deleteTaskByTaskId(model.getTaskId());
PolyvDownloaderManager.getInstance().getDbController().deleteTask(model.getTaskId());
callback.onError(task, e);
}
});
} else {
PolyvToastUtils.show(mContext, com.polyv.apsaravideo.music.R.string.polyv_load_fail);
}
} else {
PolyvToastUtils.show(mContext, com.polyv.apsaravideo.music.R.string.polyv_load_fail);
}
} catch (JSONException e) {
e.printStackTrace();
}
public void onFinish(int downloadId, String path) {
callback.onFinish(downloadId, path);
}
@Override
public void onFailure(int errorCode, String msg) {
super.onFailure(errorCode, msg);
public void onStart(int downloadId, long soFarBytes, long totalBytes, int preProgress) {
callback.onStart(downloadId, soFarBytes, totalBytes, preProgress);
}
@Override
public void onProgress(int downloadId, long soFarBytes, long totalBytes, long speed,
int progress) {
callback.onProgress(downloadId, soFarBytes, totalBytes, speed, progress);
}
});
@Override
public void onError(BaseDownloadTask task, Throwable e) {
PolyvToastUtils.show(mContext, com.polyv.apsaravideo.music.R.string.polyv_download_failed);
PolyvDownloaderManager.getInstance().deleteTaskByTaskId(model.getTaskId());
PolyvDownloaderManager.getInstance().getDbController().deleteTask(model.getTaskId());
callback.onError(task, e);
}
});
}
public void setCallback(LoadCallback callback) {
......
......@@ -6,26 +6,19 @@ import java.util.List;
public class PolyvMusicMockData {
public List<PolyvMusicFileBean> loadingMusicData() {
List<PolyvMusicFileBean> list = new ArrayList<>();
list.add(new PolyvMusicFileBean("123我爱你", "新乐尘符", "1613a1yjgxl2wls55i"));
list.add(new PolyvMusicFileBean("又见他", "Tie Yann", "1104mljclff5y415d"));
list.add(new PolyvMusicFileBean("逝年", "夏小虎", "1pj413jclfimip1xy"));
list.add(new PolyvMusicFileBean("Beautiful Life", "丁可", "11rm1tjclcgmb438c"));
list.add(new PolyvMusicFileBean("毕竟深爱过", "六哲", "1m6wecjcld7t8132d"));
list.add(new PolyvMusicFileBean("Pink Trip", "Chill Boy", "1b9avjclfj7l8vi"));
list.add(new PolyvMusicFileBean("不配做你男朋友", "张远喆", "1m3j4ejclfcu6i1p0"));
list.add(new PolyvMusicFileBean("习惯你", "3Bangz,未来星B3Rich", "13k4dijdken0r14uy"));
list.add(new PolyvMusicFileBean("80后", "南无乐队", "1x2fyjclfgnz74h6"));
list.add(new PolyvMusicFileBean("执迷", "阿金和玄子", "17316ljclfetuf4t8"));
list.add(new PolyvMusicFileBean("好好学习 天天向上", "南无乐队", "1x2fyjclfgrs32xw"));
list.add(new PolyvMusicFileBean("我的滑板鞋", "約瑟翰 龐麥郎", "18bvzijclfckn74gi"));
list.add(new PolyvMusicFileBean("带你去网吧里偷耳机", "馒头", "14w1yegjclfbt542uf"));
list.add(new PolyvMusicFileBean("舌尖上的胖胖", "馒头", "14w1yegjclfcs5j4vd"));
list.add(new PolyvMusicFileBean("勇敢的小孩", "顾颂", "11dy2aqjj0rqo7c4ha"));
list.add(new PolyvMusicFileBean("要听妈妈的话", "严梓源 吉蕊彤 周欣然", "113uwgijiujrxj61y1"));
list.add(new PolyvMusicFileBean("悄悄话", "刘贝贝 刘筱萌 夏一凡 孟子懿 王忆菡", "113uwgijiz4x9rq5ps"));
list.add(new PolyvMusicFileBean("六洲歌头『古风』", "马曲辰", "1a1jpbjclcgjtl6n"));
list.add(new PolyvMusicFileBean("思美人", "毛泽少", "17url2jcld20vy3ua"));
list.add(new PolyvMusicFileBean("武娘", "毛泽少", "17url2jcldb3sq5n9"));
list.add(new PolyvMusicFileBean("Lonesome Star", "Unicorn Heads", "0a250584a76a2a32ce02d37342477b90"));
list.add(new PolyvMusicFileBean("Succotash", "Silent Partner", "0a250584a7e4c4af672be7ac983ae759"));
list.add(new PolyvMusicFileBean("Crystal", "Vibe Tracks", "0a250584a741618d2977c312477a709f"));
list.add(new PolyvMusicFileBean("Silver Lakes", "Wes Hutchinson", "0a250584a784f509de5192270e56620a"));
list.add(new PolyvMusicFileBean("Summer Smile", "Silent Partner", "0a250584a76c62e7ce738c55d334aa2b"));
list.add(new PolyvMusicFileBean("Sunflower", "Topher Mohr and Alex Elena", "0a250584a7c409377174d33a36915334"));
list.add(new PolyvMusicFileBean("Heart Beats", "Silent Partner", "0a250584a7012a82b6d981c3c53d8537"));
list.add(new PolyvMusicFileBean("End of Summer", "The 126ers", "0a250584a7e48270650387f6a4ed80d2"));
list.add(new PolyvMusicFileBean("Give", "Silent Partner", "0a250584a7a25337a941645b178f84bb"));
list.add(new PolyvMusicFileBean("Sunday Stroll", "Huma-Huma", "0a250584a7bf0f8056dad7bf4869e406"));
list.add(new PolyvMusicFileBean("Everyday", "Jason Farnham", "0a250584a7482da668917f62e3b8eb75"));
list.add(new PolyvMusicFileBean("Alta Loma Terrace", "Wes Hutchinson", "0a250584a709ab0cb050cc92335e7903"));
list.add(new PolyvMusicFileBean("Temps", "Riot", "0a250584a774c4b28278e08fcf12b4ac"));
return list;
}
}
package com.polyv.video.common.utils;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class PolyvMd5Utils {
public static String hashKeyForDisk(String key) {
String cacheKey;
try {
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
mDigest.update(key.getBytes());
cacheKey = bytesToHexString(mDigest.digest());
} catch (NoSuchAlgorithmException e) {
cacheKey = String.valueOf(key.hashCode());
}
return cacheKey;
}
private static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
public static String getMd5(String data) {
StringBuilder sb = new StringBuilder();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] arr = md.digest(data.getBytes());
for (int i = 0; i < arr.length; ++i)
sb.append(Integer.toHexString((arr[i] & 0xFF) | 0x100).substring(1, 3));
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
}
return sb.toString();
}
public static byte[] md5(InputStream data) throws IOException {
return digest(getMd5Digest(), data);
}
public static MessageDigest getMd5Digest() {
return getDigest("MD5");
}
public static MessageDigest getDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException var2) {
throw new IllegalArgumentException(var2);
}
}
private static byte[] digest(MessageDigest digest, InputStream data) throws IOException {
return updateDigest(digest, data).digest();
}
public static MessageDigest updateDigest(MessageDigest digest, InputStream data) throws IOException {
byte[] buffer = new byte[1024];
for(int read = data.read(buffer, 0, 1024); read > -1; read = data.read(buffer, 0, 1024)) {
digest.update(buffer, 0, read);
}
return digest;
}
public static char[] encodeHex(byte[] data) {
return encodeHex(data, true);
}
private static final char[] DIGITS_LOWER;
private static final char[] DIGITS_UPPER;
static {
DIGITS_LOWER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
DIGITS_UPPER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
}
public static char[] encodeHex(byte[] data, boolean toLowerCase) {
return encodeHex(data, toLowerCase?DIGITS_LOWER:DIGITS_UPPER);
}
protected static char[] encodeHex(byte[] data, char[] toDigits) {
int l = data.length;
char[] out = new char[l << 1];
int i = 0;
for(int j = 0; i < l; ++i) {
out[j++] = toDigits[(240 & data[i]) >>> 4];
out[j++] = toDigits[15 & data[i]];
}
return out;
}
public static byte[] md5(String data) {
return md5(getBytesUtf8(data));
}
public static byte[] getBytesUtf8(String string) {
return getBytes(string, Charset.forName("UTF-8"));
}
private static byte[] getBytes(String string, Charset charset) {
return string == null?null:string.getBytes(charset);
}
public static byte[] md5(byte[] data) {
return getMd5Digest().digest(data);
}
}
......@@ -492,3 +492,5 @@
----------
1.2.0版API文档请看[v1.2.0 API](http://repo.polyv.net/android/shortvideo/javadoc/1.2.0/index.html)
1.2.1版API文档请看[v1.2.1 API](http://repo.polyv.net/android/shortvideo/javadoc/1.2.1/index.html)
\ No newline at end of file
......@@ -58,7 +58,7 @@ ext {
//upload
externalUpload = 'com.easefun.polyv:polyvShortVideoUpload:2.3.5'
//sdk
externalSVSDK = 'com.easefun.polyv:polyvShortVideoSDK:1.2.0'
externalSVSDK = 'com.easefun.polyv:polyvShortVideoSDK:1.2.1'
//Android SDK/Tools Version
externalCompileSdkVersion = 26
......@@ -66,6 +66,6 @@ ext {
externalMinSdkVersion = 15
externalTargetSdkVersion = 26
//version
externalVersionCode = 120
externalVersionName = "1.2.0"
externalVersionCode = 121
externalVersionName = "1.2.1"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment