one approach would be:
- use the
Observable.fromIterable factory method to setup the stream from the initial List<MediaChunk>
flatMap each emission from that stream and use the Observable.just factory method to create a stream of audio + video URLs from each MediaChunk instance
the result is a flattened stream of URLs for which subscribers can plug in their own onNext, onError, and onComplete handlers.
the code would look something like this:
Observable.fromIterable(
Arrays.asList(
new MediaChunk("audio-1", "video-1"),
new MediaChunk("audio-2", "video-2"),
new MediaChunk("audio-3", "video-3")
))
.flatMap(chunk -> Observable.just(chunk.audioChunkUrl, chunk.videoChunkUrl))
.subscribe(
value -> {
System.out.println("## onNext(" + value + ")");
},
error -> {
System.out.println("## onError(" + error.getMessage() + ")");
},
() -> {
System.out.println("## onComplete()");
}
);
not sure if this fits the bill, but hopefully it's enough to at least inspire some thought.
Update - example mapping emissions to Completable
Observable.fromIterable(
Arrays.asList(
new MediaChunk("audio-1", "video-1"),
new MediaChunk("audio-2", "video-2"),
new MediaChunk("audio-3", "video-3")
))
.flatMap(chunk -> Observable.just(chunk.audioChunkUrl, chunk.videoChunkUrl))
.flatMapCompletable(url -> {
return Completable.fromCallable(() -> {
return "## ...handling network call for [" + url + "]";
});
})
.subscribe(
() -> {
System.out.println("## onComplete()");
},
error -> {
System.out.println("## onError(" + error.getMessage() + ")");
}
);