View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  package example.mediarenderer;
16  
17  import org.fourthline.cling.support.avtransport.impl.state.AbstractState;
18  import org.fourthline.cling.support.avtransport.impl.state.NoMediaPresent;
19  import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable;
20  import org.fourthline.cling.support.model.AVTransport;
21  import org.fourthline.cling.support.model.MediaInfo;
22  import org.fourthline.cling.support.model.PositionInfo;
23  
24  import java.net.URI;
25  
26  /**
27   * <p>
28   * The initial state has only one possible transition and an action that
29   * triggers this transition:
30   * </p>
31   * <a class="citation" href="javacode://this" style="include: INC1"/>
32   * <p>
33   * When a client sets a new URI for playback, you have to prepare your renderer
34   * accordingly. You typically want to change the <code>MediaInfo</code> of your
35   * <code>AVTransport</code> to reflect the new "current" track, and you might
36   * want to expose information about the track, such as the playback duration.
37   * How you do this (e.g. you could actually already retrieve the file behind
38   * the URL and analyze it) is up to you.
39   * </p>
40   * <p>
41   * The <code>LastChange</code> object is how you notify control points about
42   * any changes of state, here we tell the control points that there is a new
43   * "AVTransportURI" as well as a new "CurrentTrackURI". You can add more
44   * variables and their values to the <code>LastChange</code>, depending on
45   * what actually changed - note that you should do this within a single
46   * call of <code>setEventedValue(...)</code> if you consider several changes
47   * to be atomic. (The <code>LastChange</code> will be polled and send to
48   * control points periodically in the background, more about this later.)
49   * </p>
50   * <p>
51   * The <code>AVTransport</code> will transition to the Stopped state after
52   * the URI has been set.
53   * </p>
54   */
55  public class MyRendererNoMediaPresent extends NoMediaPresent { // DOC:INC1
56  
57      public MyRendererNoMediaPresent(AVTransport transport) {
58          super(transport);
59      }
60  
61      @Override
62      public Class<? extends AbstractState> setTransportURI(URI uri, String metaData) {
63  
64          getTransport().setMediaInfo(
65                  new MediaInfo(uri.toString(), metaData)
66          );
67  
68          // If you can, you should find and set the duration of the track here!
69          getTransport().setPositionInfo(
70                  new PositionInfo(1, metaData, uri.toString())
71          );
72  
73          // It's up to you what "last changes" you want to announce to event listeners
74          getTransport().getLastChange().setEventedValue(
75                  getTransport().getInstanceId(),
76                  new AVTransportVariable.AVTransportURI(uri),
77                  new AVTransportVariable.CurrentTrackURI(uri)
78          );
79          
80          return MyRendererStopped.class;
81      }
82  } // DOC:INC1