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.Stopped; 19 import org.fourthline.cling.support.model.AVTransport; 20 import org.fourthline.cling.support.model.SeekMode; 21 22 import java.net.URI; 23 24 /** 25 * <p> 26 * The Stopped state has many possible transitions, from here a control point 27 * can decide to play, seek, skip to the next track, and so on. The following 28 * example is really not doing much, how you implement these triggers and 29 * state transitions is completely dependend on the design of your playback 30 * engine - this is only the scaffolding: 31 * </p> 32 * <a class="citation" href="javacode://this" style="include: INC1"/> 33 * <p> 34 * Each state can have two magic methods: <code>onEntry()</code> and 35 * <code>onExit()</code> - they do exactly what the name says. Don't forget 36 * to call the superclass' method if you decide to use them! 37 * </p> 38 */ 39 public class MyRendererStopped extends Stopped { // DOC:INC1 40 41 public MyRendererStopped(AVTransport transport) { 42 super(transport); 43 } 44 45 public void onEntry() { 46 super.onEntry(); 47 // Optional: Stop playing, release resources, etc. 48 } 49 50 public void onExit() { 51 // Optional: Cleanup etc. 52 } 53 54 @Override 55 public Class<? extends AbstractState> setTransportURI(URI uri, String metaData) { 56 // This operation can be triggered in any state, you should think 57 // about how you'd want your player to react. If we are in Stopped 58 // state nothing much will happen, except that you have to set 59 // the media and position info, just like in MyRendererNoMediaPresent. 60 // However, if this would be the MyRendererPlaying state, would you 61 // prefer stopping first? 62 return MyRendererStopped.class; 63 } 64 65 @Override 66 public Class<? extends AbstractState> stop() { 67 /// Same here, if you are stopped already and someone calls STOP, well... 68 return MyRendererStopped.class; 69 } 70 71 @Override 72 public Class<? extends AbstractState> play(String speed) { 73 // It's easier to let this classes' onEntry() method do the work 74 return MyRendererPlaying.class; 75 } 76 77 @Override 78 public Class<? extends AbstractState> next() { 79 return MyRendererStopped.class; 80 } 81 82 @Override 83 public Class<? extends AbstractState> previous() { 84 return MyRendererStopped.class; 85 } 86 87 @Override 88 public Class<? extends AbstractState> seek(SeekMode unit, String target) { 89 // Implement seeking with the stream in stopped state! 90 return MyRendererStopped.class; 91 } 92 } // DOC:INC1