1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package example.mediarenderer;
16
17 import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder;
18 import org.fourthline.cling.model.meta.DeviceDetails;
19 import org.fourthline.cling.model.meta.DeviceIdentity;
20 import org.fourthline.cling.model.meta.LocalDevice;
21 import org.fourthline.cling.model.meta.LocalService;
22 import org.fourthline.cling.model.types.UDADeviceType;
23 import org.fourthline.cling.model.types.UDN;
24 import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
25 import org.fourthline.cling.model.types.UnsignedIntegerTwoBytes;
26 import org.fourthline.cling.support.avtransport.impl.AVTransportService;
27 import org.fourthline.cling.support.avtransport.lastchange.AVTransportLastChangeParser;
28 import org.fourthline.cling.support.lastchange.LastChangeAwareServiceManager;
29 import org.fourthline.cling.support.lastchange.LastChangeParser;
30 import org.fourthline.cling.support.model.Channel;
31 import org.fourthline.cling.support.renderingcontrol.AbstractAudioRenderingControl;
32 import org.fourthline.cling.support.renderingcontrol.RenderingControlException;
33 import org.fourthline.cling.support.renderingcontrol.lastchange.RenderingControlLastChangeParser;
34
35
36
37
38 public class MediaRendererSampleData {
39
40 public static LocalService<AVTransportService> createAVTransportService() throws Exception {
41
42 LocalService<AVTransportService> service =
43 new AnnotationLocalServiceBinder().read(AVTransportService.class);
44
45
46
47 LastChangeParser lastChangeParser = new AVTransportLastChangeParser();
48
49 service.setManager(
50 new LastChangeAwareServiceManager<AVTransportService>(service, lastChangeParser) {
51 @Override
52 protected AVTransportService createServiceInstance() throws Exception {
53 return new AVTransportService(
54 MyRendererStateMachine.class,
55 MyRendererNoMediaPresent.class
56 );
57 }
58 }
59 );
60 return service;
61 }
62
63 public static LocalService<AudioRenderingControlService> createRenderingControlService() throws Exception {
64
65 LocalService<AudioRenderingControlService> service =
66 new AnnotationLocalServiceBinder().read(AudioRenderingControlService.class);
67
68 LastChangeParser lastChangeParser = new RenderingControlLastChangeParser();
69
70 service.setManager(
71 new LastChangeAwareServiceManager<>(
72 service,
73 AudioRenderingControlService.class,
74 lastChangeParser
75 )
76 );
77 return service;
78 }
79
80 public static LocalDevice createDevice() throws Exception {
81 return new LocalDevice(
82 new DeviceIdentity(new UDN("1111")),
83 new UDADeviceType("MediaRenderer"),
84 new DeviceDetails("My MediaRenderer"),
85 new LocalService[]{
86 createAVTransportService(),
87 createRenderingControlService()
88 }
89 );
90 }
91
92 public static class AudioRenderingControlService extends AbstractAudioRenderingControl {
93
94 @Override
95 public boolean getMute(UnsignedIntegerFourBytes instanceId, String channelName) throws RenderingControlException {
96 return false;
97 }
98
99 @Override
100 public void setMute(UnsignedIntegerFourBytes instanceId, String channelName, boolean desiredMute) throws RenderingControlException {
101
102 }
103
104 @Override
105 public UnsignedIntegerTwoBytes getVolume(UnsignedIntegerFourBytes instanceId, String channelName) throws RenderingControlException {
106 return new UnsignedIntegerTwoBytes(50);
107 }
108
109 @Override
110 public void setVolume(UnsignedIntegerFourBytes instanceId, String channelName, UnsignedIntegerTwoBytes desiredVolume) throws RenderingControlException {
111
112 }
113
114 @Override
115 protected Channel[] getCurrentChannels() {
116 return new Channel[] {
117 Channel.Master
118 };
119 }
120
121 @Override
122 public UnsignedIntegerFourBytes[] getCurrentInstanceIds() {
123 return new UnsignedIntegerFourBytes[0];
124 }
125 }
126
127 }