小白下载 v4.0版本的 MD5 值为:7dece071a9daf7f7f4f87ff1c058a020
以下内容为反编译后的 DlnaModule.java 源代码,内容仅作参考
package com.jvxiang.uniplugin_dlna;
import android.app.Activity;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.ui.component.WXImage;
import io.dcloud.common.DHInterface.IFeature;
import io.dcloud.common.constant.AbsoluteConst;
import java.util.HashMap;
import java.util.Map;
import org.cybergarage.upnp.Action;
import org.cybergarage.upnp.ControlPoint;
import org.cybergarage.upnp.Device;
import org.cybergarage.upnp.Service;
import org.cybergarage.upnp.device.DeviceChangeListener;
import org.cybergarage.upnp.event.Subscription;
public class DlnaModule extends WXSDKEngine.DestroyableModule {
ControlPoint controlPoint;
Map<String, Device> deviceMap = new HashMap();
@JSMethod(uiThread = false)
public void search(final JSCallback jSCallback) {
Log.d("search", "Search Start");
ControlPoint controlPoint = this.controlPoint;
if (controlPoint != null) {
controlPoint.stop();
}
ControlPoint controlPoint2 = new ControlPoint();
this.controlPoint = controlPoint2;
controlPoint2.start();
this.controlPoint.search();
this.controlPoint.addDeviceChangeListener(new DeviceChangeListener() {
@Override
public void deviceAdded(Device device) {
if ("urn:schemas-upnp-org:device:MediaRenderer:1".equals(device.getDeviceType())) {
Log.e("search", device.getFriendlyName());
String replace = device.getUDN().replace(Subscription.UUID, "");
DlnaModule.this.deviceMap.put(replace, device);
JSONObject jSONObject = new JSONObject();
jSONObject.put("type", (Object) "add");
jSONObject.put("name", (Object) device.getFriendlyName());
jSONObject.put("id", (Object) replace);
jSCallback.invokeAndKeepAlive(jSONObject);
}
}
@Override
public void deviceRemoved(Device device) {
if ("urn:schemas-upnp-org:device:MediaRenderer:1".equals(device.getDeviceType())) {
String replace = device.getUDN().replace(Subscription.UUID, "");
DlnaModule.this.deviceMap.remove(replace);
JSONObject jSONObject = new JSONObject();
jSONObject.put("type", (Object) AbsoluteConst.XML_REMOVE);
jSONObject.put("name", (Object) device.getFriendlyName());
jSONObject.put("id", (Object) replace);
jSCallback.invokeAndKeepAlive(jSONObject);
}
}
});
}
@JSMethod(uiThread = false)
public void play(JSONObject jSONObject, JSCallback jSCallback) {
if (this.mWXSDKInstance.getContext() instanceof Activity) {
String string = jSONObject.getString("id");
String string2 = jSONObject.getString("url");
String string3 = jSONObject.getString(AbsoluteConst.JSON_KEY_TITLE);
if (string2 == null || string2.isEmpty()) {
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("type", (Object) "error");
jSONObject2.put(NotificationCompat.CATEGORY_MESSAGE, (Object) "播放地址不能为空");
jSCallback.invoke(jSONObject2);
} else if (!this.deviceMap.containsKey(string)) {
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("type", (Object) "error");
jSONObject3.put(NotificationCompat.CATEGORY_MESSAGE, (Object) "id对应的设备不存在");
jSCallback.invoke(jSONObject3);
} else {
Service service = this.deviceMap.get(string).getService("urn:schemas-upnp-org:service:AVTransport:1");
Action action = service.getAction("SetAVTransportURI");
if (action == null) {
JSONObject jSONObject4 = new JSONObject();
jSONObject4.put("type", (Object) "error");
jSONObject4.put(NotificationCompat.CATEGORY_MESSAGE, (Object) "投屏出错,请重试");
jSCallback.invoke(jSONObject4);
return;
}
action.setArgumentValue("InstanceID", "0");
action.setArgumentValue("CurrentURI", string2);
if (string3 != null && !string3.isEmpty()) {
String format = String.format("<?xml version=\"1.0\" encoding=\"utf-8\"?><DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:sec=\"http://www.sec.co.kr/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"><item id=\"f-0\" parentID=\"0\" restricted=\"0\"><dc:title>%s</dc:title><dc:creator>Anonymous</dc:creator><upnp:class>object.item.videoItem.movie</upnp:class><res protocolInfo=\"http-get:*:video/mp4:*\">%s</res></item></DIDL-Lite>", string3, string2);
Log.e(IFeature.F_CONSOLE, format);
action.setArgumentValue("CurrentURIMetaData", format);
}
if (action.postControlAction()) {
Action action2 = service.getAction("Play");
action2.setArgumentValue("InstanceID", "0");
action2.setArgumentValue("Speed", "1");
if (!action2.postControlAction()) {
Log.e("upnpErr", action2.getStatus().getDescription());
JSONObject jSONObject5 = new JSONObject();
jSONObject5.put("type", (Object) "error");
jSONObject5.put(NotificationCompat.CATEGORY_MESSAGE, (Object) action2.getStatus().getDescription());
jSCallback.invoke(jSONObject5);
return;
}
JSONObject jSONObject6 = new JSONObject();
jSONObject6.put("type", (Object) WXImage.SUCCEED);
jSONObject6.put(NotificationCompat.CATEGORY_MESSAGE, (Object) "投屏成功");
jSCallback.invoke(jSONObject6);
return;
}
JSONObject jSONObject7 = new JSONObject();
jSONObject7.put("type", (Object) "error");
jSONObject7.put(NotificationCompat.CATEGORY_MESSAGE, (Object) "投屏发送失败");
jSCallback.invoke(jSONObject7);
}
}
}
@Override
public void destroy() {
this.controlPoint = null;
}
}