File Source: AmarokSource.java
/*
P/P * Method: com.dmdirc.addons.mediasource_dcop.AmarokSource__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.mediasource_dcop;
24
25 import com.dmdirc.addons.nowplaying.MediaSource;
26 import com.dmdirc.addons.nowplaying.MediaSourceState;
27
28 import java.util.List;
29
30 /**
31 * Uses DCOP to retrieve now playing info from Amarok.
32 *
33 * @author chris
34 */
35 public class AmarokSource implements MediaSource {
36
37 /** Instantiates the media source. */
/*
P/P * Method: void com.dmdirc.addons.mediasource_dcop.AmarokSource()
*/
38 public AmarokSource() {
39 //Do nothing
40 }
41
42 /** {@inheritDoc} */
43 @Override
44 public MediaSourceState getState() {
/*
P/P * Method: MediaSourceState getState()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
* java.util.List:get(...)@47 != null
*
* Postconditions:
* return_value in Addr_Set{&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#1),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#2),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#3),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#4),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#5)}
*
* Test Vectors:
* java.lang.Integer:parseInt(...)@49: {0}, {1}, {2}, {-231..-1, 3..232-1}
* java.util.List:size(...)@46: {-231..0}, {1..232-1}
*/
45 final List<String> res = DcopMediaSourcePlugin.getDcopResult("dcop amarok player status");
46 if (res.size() > 0) {
47 final String result = res.get(0).trim();
48 try {
49 final int status = (Integer.parseInt(result));
50 switch (status) {
51 case 0:
52 return MediaSourceState.STOPPED;
53 case 1:
54 return MediaSourceState.PAUSED;
55 case 2:
56 return MediaSourceState.PLAYING;
57 default:
58 return MediaSourceState.NOTKNOWN;
59 }
60 } catch (NumberFormatException nfe) {
61 return MediaSourceState.CLOSED;
62 }
63 } else {
64 return MediaSourceState.CLOSED;
65 }
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public String getAppName() {
/*
P/P * Method: String getAppName()
*
* Postconditions:
* return_value == &"Amarok"
*/
71 return "Amarok";
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public String getArtist() {
/*
P/P * Method: String getArtist()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
77 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player artist").get(0);
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public String getTitle() {
/*
P/P * Method: String getTitle()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
83 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player title").get(0);
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public String getAlbum() {
/*
P/P * Method: String getAlbum()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
89 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player album").get(0);
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public String getLength() {
/*
P/P * Method: String getLength()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
95 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player totalTime").get(0);
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public String getTime() {
/*
P/P * Method: String getTime()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
101 return DcopMediaSourcePlugin.getDcopResult(
102 "dcop amarok player currentTime").get(0);
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 public String getFormat() {
/*
P/P * Method: String getFormat()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
108 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player type").get(0);
109 }
110
111 /** {@inheritDoc} */
112 @Override
113 public String getBitrate() {
/*
P/P * Method: String getBitrate()
*
* Presumptions:
* com.dmdirc.plugins.ExportedService:execute(...)@61 != null
*
* Postconditions:
* init'ed(return_value)
*/
114 return DcopMediaSourcePlugin.getDcopResult("dcop amarok player bitrate").get(0);
115 }
116
117 }
SofCheck Inspector Build Version : 2.17854
| AmarokSource.java |
2009-Jun-25 01:54:24 |
| AmarokSource.class |
2009-Sep-02 17:04:15 |