Skip to content

Commit c62c10b

Browse files
committed
Refactored getMediaStatus() to return a list of MediaStatus instances instead of only the first instance
1 parent 35f1af1 commit c62c10b

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

src/main/java/org/digitalmediaserver/cast/Channel.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.security.KeyManagementException;
3030
import java.security.NoSuchAlgorithmException;
3131
import java.security.SecureRandom;
32+
import java.util.Collections;
3233
import java.util.HashMap;
3334
import java.util.HashSet;
3435
import java.util.Iterator;
@@ -961,38 +962,38 @@ public boolean isSessionClosed(@Nullable Session session) {
961962
}
962963

963964
/**
964-
* Request a {@link MediaStatus} from the application with the specified
965-
* {@link Session}, using {@value #DEFAULT_RESPONSE_TIMEOUT} as the timeout
966-
* value.
965+
* Request a list of {@link MediaStatus}es from the application with the
966+
* specified {@link Session}, using {@value #DEFAULT_RESPONSE_TIMEOUT} as
967+
* the timeout value.
967968
*
968969
* @param session the {@link Session} to use.
969-
* @return The resulting {@link MediaStatus}.
970+
* @return The resulting {@link List} of {@link MediaStatus}.
970971
* @throws IOException If the response times out or an error occurs during
971972
* the operation.
972973
*
973974
* @apiNote This operation is blocking.
974975
*/
975-
@Nullable
976-
public MediaStatus getMediaStatus(@Nonnull Session session) throws IOException {
976+
@Nonnull
977+
public List<MediaStatus> getMediaStatus(@Nonnull Session session) throws IOException {
977978
return getMediaStatus(session, DEFAULT_RESPONSE_TIMEOUT);
978979
}
979980

980981
/**
981-
* Request a {@link MediaStatus} from the application with the specified
982-
* {@link Session}.
982+
* Request a list of {@link MediaStatus}es from the application with the
983+
* specified {@link Session}.
983984
*
984985
* @param session the {@link Session} to use.
985986
* @param responseTimeout the response timeout in milliseconds. If zero or
986987
* negative, {@value #DEFAULT_RESPONSE_TIMEOUT} will be used.
987-
* @return The resulting {@link MediaStatus}.
988+
* @return The resulting {@link List} of {@link MediaStatus}.
988989
* @throws IllegalArgumentException If {@code session} is {@code null}.
989990
* @throws IOException If the response times out or an error occurs during
990991
* the operation.
991992
*
992993
* @apiNote This operation is blocking.
993994
*/
994-
@Nullable
995-
public MediaStatus getMediaStatus(@Nonnull Session session, long responseTimeout) throws IOException {
995+
@Nonnull
996+
public List<MediaStatus> getMediaStatus(@Nonnull Session session, long responseTimeout) throws IOException {
996997
requireNotNull(session, "session");
997998
MediaStatusResponse status = send(
998999
session,
@@ -1003,7 +1004,10 @@ public MediaStatus getMediaStatus(@Nonnull Session session, long responseTimeout
10031004
MediaStatusResponse.class,
10041005
responseTimeout
10051006
);
1006-
return status == null || status.getStatuses().isEmpty() ? null : status.getStatuses().get(0);
1007+
if (status == null) {
1008+
return Collections.emptyList();
1009+
}
1010+
return status.getStatuses();
10071011
}
10081012

10091013
/**

src/main/java/org/digitalmediaserver/cast/Session.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -941,25 +941,25 @@ public MediaStatus setVolume(
941941
}
942942

943943
/**
944-
* Requests an updated {@link MediaStatus} from the remote application. This
944+
* Requests a list of updated {@link MediaStatus}es from the remote application. This
945945
* method is always blocking.
946946
* <p>
947947
* This can only succeed if the remote application supports the
948948
* {@link CastDevice#CAST_MEDIA_NAMESPACE}.
949949
*
950-
* @return The resulting {@link MediaStatus} if a reply is received in time,
951-
* or {@code null} if a timeout occurs.
952-
* @throws IOException If an error occurs during the operation.
950+
* @return The resulting {@link List} of {@link MediaStatus}.
951+
* @throws IOException If the response times out or an error occurs during
952+
* the operation.
953953
*
954954
* @apiNote This operation is blocking.
955955
*/
956-
@Nullable
957-
public MediaStatus getMediaStatus() throws IOException {
956+
@Nonnull
957+
public List<MediaStatus> getMediaStatus() throws IOException {
958958
return channel.getMediaStatus(this);
959959
}
960960

961961
/**
962-
* Requests an updated {@link MediaStatus} from the remote application. This
962+
* Requests a list of updated {@link MediaStatus}es from the remote application. This
963963
* method is always blocking.
964964
* <p>
965965
* This can only succeed if the remote application supports the
@@ -968,14 +968,14 @@ public MediaStatus getMediaStatus() throws IOException {
968968
* @param responseTimeout the response timeout in milliseconds. If zero or
969969
* negative, {@link Channel#DEFAULT_RESPONSE_TIMEOUT} will be
970970
* used.
971-
* @return The resulting {@link MediaStatus} if a reply is received in time,
972-
* or {@code null} if a timeout occurs.
973-
* @throws IOException If an error occurs during the operation.
971+
* @return The resulting {@link List} of {@link MediaStatus}.
972+
* @throws IOException If the response times out or an error occurs during
973+
* the operation.
974974
*
975975
* @apiNote This operation is blocking.
976976
*/
977-
@Nullable
978-
public MediaStatus getMediaStatus(long responseTimeout) throws IOException {
977+
@Nonnull
978+
public List<MediaStatus> getMediaStatus(long responseTimeout) throws IOException {
979979
return channel.getMediaStatus(this, responseTimeout);
980980
}
981981

0 commit comments

Comments
 (0)