我正在开发一个 android UPnP/DLNA 应用程序。我有一个控制点,可以在其中将文件从媒体服务器流式传输到渲染器。我可以在播放过程中暂停/播放和停止文件,但我似乎无法弄清楚如何将搜索栏集成到控制点以显示播放文件的进度并能够与搜索栏进行交互。我正在使用 Cling Java 库来创建应用程序。如果有人有任何可以帮助我的例子,我将不胜感激。
谢谢
我尝试实现 SubscriptionCallback 示例并订阅 LastChange
SubscriptionCallback callback = new SubscriptionCallback(service, 600) { // Timeout in seconds
public void established(GENASubscription sub) {
System.out.println("Established: " + sub.getSubscriptionId());
}
@Override
public void failed(GENASubscription sub, UpnpResponse response, Exception ex) {
System.err.println(
createDefaultFailureMessage(response, ex)
);
}
@Override
public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {
// Reason should be null, or it didn't end regularly
}
public void eventReceived(GENASubscription sub) {
System.out.println("Event: " + sub.getCurrentSequence().getValue());
try {
lastChange = new LastChange(
new AVTransportLastChangeParser(),
sub.getCurrentValues().get("LastChange").toString()
);
} catch (Exception ex) {
log.warning("Error parsing LastChange event content: " + ex);
return;
}
Map<String, StateVariableValue> values = sub.getCurrentValues();
StateVariableValue status = values.get("Status");
System.out.println("Status is: " + status.toString());
}
public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {
System.out.println("Missed events: " + numberOfMissedEvents);
}
@Override
protected void failed(GENASubscription arg0,
UpnpResponse arg1, Exception arg2, String arg3) {
}
};
upnpService.getControlPoint().execute(callback);
然后我尝试获取当前播放曲目的持续时间:
System.out.println("Duration: "+lastChange.getEventedValue(0, AVTransportVariable.CurrentTrackDuration.class).getValue());
但这会返回 NullPointerException。
有任何想法吗???????
** * ** * ** * ** *更新* ** * ** * ** * *
我一直在尝试实现 Seek() 但没有成功。
我有我的搜索栏和侦听器,但是当我将搜索栏拖到新位置时它一直失败。
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)
{
Log.i("SEEKTIME", "time:" + arg1);
upnpService.getControlPoint().execute(new Seek(service, SeekMode.REL_TIME, arg0.toString())
{
@Override
public void success(ActionInvocation invocation)
{
//super.success(invocation);
Log.i("SEEKSUCCESS", "success seek");
}
@Override
public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2)
{
Log.i("SEEKFAIL", "fail seek");
}
});
}
任何建议为什么这会失败