-
Notifications
You must be signed in to change notification settings - Fork 10
/
UUpnpDMC.pas
682 lines (600 loc) · 19.1 KB
/
UUpnpDMC.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
(*
* (C) Copyright 2012 Ruud Ermers.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Contributors:
* Ruud Ermers
* History
2012-12-28 1.0 Initial Release
Usage:
UUpnpDMC is a class that implements a DLNA DMC (Digital Media Controller)
You can browse the available servers and renderers on your system.
Once found, you can select an item from the server and play it on a renderer.
Then you can pause, stop, play, seek that item
You create a UUpnpDMC object by calling _create_, supplying an owner and a TStrings (not NIL) used as LOg
You can search devices by _SearchDevices_
Set _OnDeviceListChanged_ to receive notifaction on Devices available
Then retrieve Servers and Renderers by inpecting _ServerCount_ and _GetServerName_ etc.
Select a Server with _SetServerIndex_, the same for a Renderer
Browse the Server tree with _BrowseRoot_ and subdirectories with _BrowseIndex_ go back with _Back_
Inspect items with _GetItemName_ and _ItemCount_
Select an item with _SetItemIndex_
Now you can Play, Pause, Seek, SetPosition etc the item with the corresponding methods.
You can retrieve information bij GetPosition and GetPlayStatus
Notes:
1. Tested with Delphi 2010
2. You might test this with the supplied example
*)
unit UUpnpDMC;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, ExtCtrls,Graphics, Controls, Forms, Generics.Collections,
Dialogs,UPNPLib_TLB, StdCtrls, OleServer, ComObj, ActiveX, ComCtrls,xmldom, XMLIntf, msxmldom, XMLDoc, UAVTransportService;
type
TDeviceListItem = class
UPnPDevice:IUPnPDevice;
constructor Create(IUPnPDevice:IUPnPDevice);
end;
TDevicelist = TList<TDeviceListItem>;
TItemListItem = TDictionary<String,String>;
TItemList = Tlist<TItemListItem>;
TMediaRendererControl = class
private
RendererDevice:IUPnPDevice;
AVTransport: TAVTransportService;
mDuration:integer;
public
constructor Create;
procedure SetRendererDevice(arenderer:IUPnPDevice);
destructor Destroy; override;
property Duration:integer read mDuration;
procedure SetAVTransportURI(uri,meta,duration:string);
end;
TUpnpDMC = class
private
owner:TComponent;
class var FLog:TStrings;
RendererList: TDevicelist;
ServerList: TDevicelist;
ItemList:TItemList;
FitemAsString:TStringList;
FindDataServer,FindDataRenderer:integer;
FRendererIndex,FServerIndex,FItemIndex:integer;
ItemStack:TStack<integer>;
class var FXMLDoc:TXMLDocument;
UPnPDeviceFinder: TUPnPDeviceFinder;
FCallback: IUPnPDeviceFinderCallback;
FCallbackService:IUPnPServiceCallback;
MediaRenderer:TMediaRendererControl;
FOnDeviceListChanged: TNotifyEvent;
procedure SetBrowseList(s: String);
procedure Browse(StartIndex:integer);
function GetDeviceListChanged:TNotifyEvent;
procedure SetOnDeviceListChanged(const Value: TNotifyEvent);
procedure DeviceAdded(lFindData: integer; const pDevice: IUPnPDevice);
procedure DeviceRemoved(lFindData: integer; bstrUDN: string);
public
class property XMLDoc:TXMLDocument read FXMLDoc write FXMLDoc;
class property Log:TStrings read FLog write FLog;
constructor Create(aOwner:TComponent;aLog:TStrings);
procedure SearchDevices;
property OnDeviceListChanged:TNotifyEvent read GetDeviceListChanged write SetOnDeviceListChanged;
function ServerCount:integer;
procedure SetServerIndex(index:integer);
function GetServerName(index:integer):string;
function FindServer(name:string):integer;
function RendererCount:integer;
procedure SetRendererIndex(index:integer);
function GetRendererName(index:integer):string;
function FindRenderer(name:string):integer;
function ItemCount:integer;
procedure SetItemIndex(index:integer);
function GetItemName(index:integer):string;
function items:TStringList;
function BrowseItems(index:integer):boolean;
procedure BrowseItemsRoot;
procedure Back;
procedure PlayItem;
procedure Stop;
procedure Pause;
procedure Play;
function PlayStatus:integer; // type TPlayStatus = (PSPlay,PSPaused,PSStop, Undefined=3);
function GetPosition:integer;
function SetPosition(position:integer):boolean;
function GetItemDuration:integer;
procedure Seek(amount:integer);
end;
function UpnpSecondsToTime(n:integer):string;
implementation
uses uComEnumerator;
function GetService(device:IUPnPDevice; service: string):IUPnPService;forward;
function UpnpTimeToSeconds(s:string):integer;forward;
var tempDevice : IUnknown;
tempService: IUnknown;
type TCallback = class(TInterfacedObject, IUPnPDeviceFinderCallback, IUnknown)
protected
function DeviceAdded(lFindData: integer; const pDevice: IUPnPDevice): HRESULT;stdcall;
function DeviceRemoved(lFindData: integer; const bstrUDN: widestring):HRESULT; stdcall;
function SearchComplete(lFindData: integer): HRESULT; stdcall;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
public
UpnpDMC:TUpnpDMC;
end;
TServiceCallback = class(TInterfacedObject, IUPnPServiceCallback)
protected
function StateVariableChanged(const pus: IUPnPService; pcwszStateVarName:PWideChar; vaValue: OleVariant): HResult; stdcall;
function ServiceInstanceDied(const pus: IUPnPService): HResult; stdcall;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
end;
TPlayItem = class
private
mUri,mDuration:string;
function GetDataFromId(Service:IUPnPService;id: string): string;
public
constructor Create(server:IUPnPDevice;item:TItemListItem);
end;
function TCallback.DeviceAdded(lFindData: integer; const pDevice: IUPnPDevice):HRESULT;
begin
UpnpDMC.DeviceAdded(lFindData,pDevice);
result := S_OK;
end;
function TCallback.DeviceRemoved(lFindData: integer; const bstrUDN: widestring):HRESULT;
begin
TUpnpDMC.Log.Add('Device removed: ' + bstrUDN);
UpnpDMC.DeviceRemoved(lFindData,bstrUDN);
result := S_OK;
end;
function TCallback.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
result := Inherited QueryInterface(IID, obj);
end;
function TCallback.SearchComplete(lFindData: integer): HRESULT;
begin
TUpnpDMC.Log.Add('Search Complete');
result := S_OK;
end;
function TServiceCallback.StateVariableChanged(const pus: IUPnPService;pcwszStateVarName: PWideChar; vaValue: OleVariant): HRESULT;
var
output: string;
varname: WideString;
Value: string;
begin
varname:=WideString(pcwszStateVarName);
if VarType(vaValue)=varOleStr then
Value := vaValue;
output:='State changed: '+pus.Id +' VarName: '+varname+' Varianttype:'+VarTypeAsText(VarType(vaValue))+' Value '+Value;
TUpnpDMC.Log.Add(output);
result := S_OK;
end;
function TServiceCallback.ServiceInstanceDied(const pus: IUPnPService): HRESULT;
var
output: string;
begin
output:='Service died: '+pus.Id;
TUpnpDMC.Log.Add(output);
result := S_OK;
end;
function TServiceCallback.QueryInterface(const IID: TGUID; out Obj):
HResult;
begin
result := Inherited QueryInterface(IID, obj);
end;
{ TDeviceListItem }
constructor TDeviceListItem.Create(IUPnPDevice: IUPnPDevice);
begin
UPnPDevice:=IUPnPDevice;
end;
{ TMediaRenderer }
procedure TMediaRendererControl.SetRendererDevice(arenderer: IUPnPDevice);
VAR services: IUPnPServices;
Iservice: IInterface;
MyService:IUPnPService;
s:string;
begin
RendererDevice:=arenderer;
MyService:=NIL;
if RendererDevice<>NIL then
begin
services:=arenderer.Services;
for Iservice in GetCOMEnumerator(services._NewEnum) do
begin
s:=(Iservice as IUPnPService).ServiceTypeIdentifier;
TUpnpDMC.Log.Add('Service: '+s);
if s = 'urn:schemas-upnp-org:service:AVTransport:1'
then MyService:=IUPnPService(Iservice);
end;
end;
if MyService = NIL then
TUpnpDMC.Log.Add('AVTransport Not Found:');
AVTransport.SetAVTransportService(MyService);
end;
constructor TMediaRendererControl.Create;
begin
AVTransport:=TAVTransportService.Create(TUpnpDMC.Log);
SetRendererDevice(NIL);
end;
{ TUpnpDMC }
procedure TUpnpDMC.Back;
begin
if ItemStack.Count < 2 then exit;
ItemStack.Pop;
Browse(ItemStack.Pop);
FItemIndex:=-1;
end;
procedure TUpnpDMC.Browse(StartIndex:integer);
VAR services: IUPnPServices;
Iservice: IInterface;
MyService:IUPnPService;
ovIn,ovOut : OleVariant;
s:string;
begin
if (FServerIndex<0) or (FServerIndex>=ServerList.Count) then exit;
ItemStack.Push(StartIndex);
services:=ServerList[FServerIndex].UPnPDevice.Services;
for Iservice in GetCOMEnumerator(services._NewEnum) do
begin
s:=(Iservice as IUPnPService).ServiceTypeIdentifier;
TUpnpDMC.Log.Add('Service: '+s);
if s = 'urn:schemas-upnp-org:service:ContentDirectory:1'
then
MyService:=IUPnPService(Iservice);
end;
//ContentBrowser.Items.Clear;
ovIn := VarArrayCreate([0, 5], varVariant);
ovIn[0]:= inttostr(StartIndex);
ovIn[1]:= 'BrowseDirectChildren';
ovIn[2]:= '';
ovIn[3]:= 0;
ovIn[4]:= 0;
ovIn[5]:= '';
ovOut := VarArrayCreate([0, 0], varVariant);
MyService.InvokeAction('Browse', ovIn, ovOut);
Log.Text:=ovOut[0];
SetBrowseList(ovOut[0]);
end;
procedure TUpnpDMC.SetBrowseList(s:String);
procedure AddNodes(ANode:IXMLNode);
VAR i:integer;
item:TItemListItem;
child:IXMLNode;
id:string;
begin
while ANode<>NIL do
begin
// do something with ANode
id:=ANode.AttributeNodes['id'].Text;
item:=TItemListItem.Create;
item.add('id',id);
for I:=0 to ANode.ChildNodes.Count-1 do
begin
child:=ANode.ChildNodes[i];
item.Add(child.NodeName,child.Text);
end;
try
item.Add('uri',ANode.Text);
except
item.add('uri','');
end;
item.Add('xml',ANode.XML);
ItemList.Add(item);
ANode := ANode.NextSibling;
end;
end;
VAR StartItemNode : IXMLNode;
begin
XMLDoc.Active:=false;
XMLDoc.LoadFromXML(s);
XMLDoc.Active:=True;
ItemList.Clear;
StartItemNode := XMLDoc.DocumentElement.ChildNodes.FindNode('container') ;
AddNodes(StartItemNode);
StartItemNode := XMLDoc.DocumentElement.ChildNodes.FindNode('item') ;
AddNodes(StartItemNode);
end;
procedure TUpnpDMC.SetItemIndex(index: integer);
begin
FItemIndex:=index;
end;
function TUpnpDMC.BrowseItems(index: integer): boolean;
begin
try
Browse(StrToInt(ItemList[index]['id']));
result:=true;
except
result:=false;
end
end;
procedure TUpnpDMC.BrowseItemsRoot;
begin
Browse(0);
end;
constructor TUpnpDMC.Create(aOwner:TComponent;aLog: TStrings);
begin
Owner:=aOwner;
Log:=aLog;
tempDevice := TCallback.Create;
OLECheck(tempDevice.QueryInterface(IUPnPDeviceFinderCallback,FCallback));
(tempDevice as TCallBack).UpnpDMC:=self;
tempService := TServiceCallback.Create;
OLECheck(tempService.QueryInterface(IUPnPServiceCallback,FCallbackService));
ServerList:=TDevicelist.Create;
RendererList:=TDevicelist.Create;
ItemList:=TItemList.Create;
ItemStack:=TStack<integer>.Create;
FitemAsString:=TStringList.Create;
UPnPDeviceFinder:=TUPnPDeviceFinder.Create(Owner);
XMLDoc:=TXMLDocument.Create(owner);
MediaRenderer:=TMediaRendererControl.Create;
end;
procedure TUpnpDMC.DeviceAdded(lFindData: integer; const pDevice: IUPnPDevice);
begin
if lFindData = FindDataServer then
ServerList.Add(TDeviceListItem.Create(pDevice))
else
RendererList.Add(TDeviceListItem.Create(pDevice));
if assigned(FOnDeviceListChanged) then OnDeviceListChanged(self);
end;
procedure TUpnpDMC.DeviceRemoved(lFindData: integer; bstrUDN: string);
function find(list:TDevicelist;udn:string):integer;
VAR i:integer;
begin
result:=-1;
for i:=0 to list.Count-1 do with list[i] do
if list[i].UPnPDevice.UniqueDeviceName = udn then result:=i;
end;
VAR index:integer;
list:TDevicelist;
begin
if lFindData = FindDataServer then list:=ServerList
else list:=RendererList;
index:=find(list,bstrUDN);
if index>=0 then
begin
if list[index].UPnPDevice = MediaRenderer.RendererDevice then
MediaRenderer.SetRendererDevice(NIL);
list.Delete(index);
end;
if assigned(FOnDeviceListChanged) then OnDeviceListChanged(self);
end;
function TUpnpDMC.GetDeviceListChanged: TNotifyEvent;
begin
result:=FOnDeviceListChanged;
end;
procedure TUpnpDMC.Seek(amount: integer);
VAR n:integer;
begin
n:=GetPosition+amount;
if n<0 then n:=0;
if n>GetItemDuration then n:=GetItemDuration-1;
SetPosition(n);
end;
function TUpnpDMC.GetItemDuration: integer;
begin
result:=MediaRenderer.Duration;
end;
function TUpnpDMC.GetItemName(index: integer): string;
VAR id,title:string;
begin
id:=ItemList[index].Items['id'];
title:=ItemList[index].Items['dc:title'];
result:=id+ ' ' +title;
end;
function TUpnpDMC.GetPosition: integer;
begin
if (MediaRenderer.AVTransport.PlayStatus =3) then result:=0
else result:=UpnpTimeToSeconds(MediaRenderer.AVTransport.GetPosition);
end;
function TUpnpDMC.GetRendererName(index: integer): string;
begin
result:=RendererList[index].UPnPDevice.FriendlyName;
end;
function TUpnpDMC.GetServerName(index: integer): string;
begin
result:=ServerList[index].UPnPDevice.FriendlyName;
end;
function TUpnpDMC.ItemCount: integer;
begin
result:=ItemList.Count;
end;
procedure TUpnpDMC.Pause;
begin
MediaRenderer.AVTransport.Pause;
end;
procedure TUpnpDMC.Play;
begin
MediaRenderer.AVTransport.Play;
end;
procedure TUpnpDMC.PlayItem;
VAR aPlayItem:TPlayItem;
xml:string;
begin
if (FRendererIndex<0) or (FRendererIndex>=RendererCount) then exit;
if (FServerIndex<0) or (FServerIndex>=ServerCount) then exit;
if (FItemIndex<0) or (FItemIndex>=ItemCount) then exit;
MediaRenderer.AVTransport.Stop;
aPlayItem:=TPlayItem.Create(ServerList[FServerIndex].UPnPDevice,ItemList[FItemIndex]);
MediaRenderer.SetRendererDevice(RendererList[FRendererIndex].UPnPDevice);
xml:=''; // ItemList[FItemIndex]['xml'];
MediaRenderer.SetAVTransportURI(aPlayItem.mUri, xml,aPlayItem.mDuration);
aPlayItem.Free;
MediaRenderer.AVTransport.Play;
end;
function TUpnpDMC.PlayStatus: integer; type TPlayStatus = (PSPlay,PSPaused,PSStop);
begin
result:= MediaRenderer.AVTransport.PlayStatus;
end;
function TUpnpDMC.RendererCount: integer;
begin
result:=RendererList.Count;
end;
procedure TUpnpDMC.SearchDevices;
begin
ServerList.clear;
FindDataServer:=UPnPDeviceFinder.CreateAsyncFind('urn:schemas-upnp-org:device:MediaServer:1', 0, Fcallback);
UPnPDeviceFinder.StartAsyncFind(FindDataServer);
RendererList.Clear;
FindDataRenderer:=UPnPDeviceFinder.CreateAsyncFind('urn:schemas-upnp-org:device:MediaRenderer:1', 0, Fcallback);
UPnPDeviceFinder.StartAsyncFind(FindDataRenderer);
end;
function TUpnpDMC.ServerCount: integer;
begin
Result:=ServerList.Count;
end;
procedure TUpnpDMC.SetOnDeviceListChanged(const Value: TNotifyEvent);
begin
FOnDeviceListChanged := Value;
end;
function TUpnpDMC.SetPosition(position: integer): boolean;
begin
result:=MediaRenderer.AVTransport.SetPosition(UpnpSecondsToTime(position));
end;
function TUpnpDMC.FindRenderer(name: string): integer;
VAR i:integer;
begin
result:=-1;
for i:=0 to RendererCount-1 do
if RendererList[i].UPnPDevice.FriendlyName = name then
begin
result:=i;
exit;
end;
end;
procedure TUpnpDMC.SetRendererIndex(index: integer);
begin
FRendererIndex:=index;
end;
function TUpnpDMC.FindServer(name: string): integer;
VAR i:integer;
begin
result:=-1;
for i:=0 to ServerCount-1 do
if ServerList[i].UPnPDevice.FriendlyName = name then
begin
result:=i;
exit;
end;
end;
procedure TUpnpDMC.SetServerIndex(index: integer);
begin
FServerIndex:=index;
end;
procedure TUpnpDMC.Stop;
begin
MediaRenderer.AVTransport.Stop;
end;
function TUpnpDMC.items: TStringList;
VAR i:integer;
begin
with FitemAsString do
begin
clear;
for i:=0 to ItemCount-1 do
Add(ItemList[i]['dc:title']);
end;
result:=FitemAsString;
end;
{ TPlayItem }
constructor TPlayItem.Create(server: IUPnPDevice; item: TItemListItem);
VAR services: IUPnPServices;
Iservice: IInterface;
MyService:IUPnPService;
s:string;
begin
services:=server.Services;
for Iservice in GetCOMEnumerator(services._NewEnum) do
begin
s:=(Iservice as IUPnPService).ServiceTypeIdentifier;
TUpnpDMC.Log.Add('Service: '+s);
if s = 'urn:schemas-upnp-org:service:ContentDirectory:1'
then begin
MyService:=IUPnPService(Iservice);
GetDataFromId(MyService,item['id']);
end;
end;
end;
function TPlayItem.GetDataFromId(Service:IUPnPService;id: string): string;
VAR ovIn,ovOut : OleVariant;
s:string;
VAR ItemNode : IXMLNode;
begin
ovIn := VarArrayCreate([0, 5], varVariant);
ovIn[0]:= id;
ovIn[1]:= 'BrowseMetadata';
ovIn[2]:= 'upnp:album,upnp:artist,upnp:genre,upnp:title,res@size,res@duration,res@bitrate,res@sampleFrequency,res@bitsPerSample,res@nrAudioChannels,res@protocolInfo,res@protection,res@importUri';
ovIn[3]:= 0;
ovIn[4]:= 1;
ovIn[5]:= '';
ovOut := VarArrayCreate([0, 3], varVariant);
Service.InvokeAction('Browse',ovIn,ovOut);
s:=ovOut[0];
TUpnpDMC.Log.Add(s);
TUpnpDMC.XMLDoc.Active:=false;
TUpnpDMC.XMLDoc.LoadFromXML(s);
TUpnpDMC.XMLDoc.Active:=True;
//TUpnpDMC.Log.Add(form4.XMLDoc.DocumentElement.ChildNodes[0].Text);
ItemNode := TUpnpDMC.XMLDoc.DocumentElement.ChildNodes[0].ChildNodes.FindNode('res') ;
mDuration:=ItemNode.AttributeNodes['duration'].Text;
TUpnpDMC.Log.Add(ItemNode.Text);
mUri:=ItemNode.Text;
end;
function GetService(device:IUPnPDevice; service: string):IUPnPService;
VAR services: IUPnPServices;
Iservice: IInterface;
s:string;
begin
services:=device.Services;
for Iservice in GetCOMEnumerator(services._NewEnum) do
begin
s:=(Iservice as IUPnPService).ServiceTypeIdentifier;
if s = service then
result:=IUPnPService(Iservice);
end;
end;
destructor TMediaRendererControl.Destroy;
begin
AVTransport.Free;
end;
procedure TMediaRendererControl.SetAVTransportURI(uri, meta,duration: string);
VAR s:string;
p:integer;
begin
try
s:=duration;
p:=pos('.',s);
if p>0 then s:=Copy(s,1,p-1);
mDuration:=UpnpTimeToSeconds(s);
except
mDuration:=0;
end;
AVTransport.SetAVTransportURI(0, uri,meta);
end;
function UpnpTimeToSeconds(s:string):integer;
VAR i,p:integer;
begin
p:=0;
result:=0;
for i:=0 to length(s)-1 do if s[i]=':' then p:=i;
try
if p=0 then result:=StrToInt(s)
else result:=60*UpnpTimeToSeconds(Copy(s,1,p-1))+StrToInt(Copy(s,p+1));
except end;
end;
function UpnpSecondsToTime(n:integer):string;
function TwoStr(n:integer):string;
begin
if n<10 then result:='0'+inttostr(n)
else result:=inttostr(n)
end;
begin
result:=TwoStr(n DIV 3600) + ':'+ TwoStr(n DIV 60 MOD 60) + ':'+TwoStr(n MOD 60);
end;
end.