Skip to content

Commit

Permalink
Adjustments for #742 per deeper analysis of other DataSource implemen…
Browse files Browse the repository at this point in the history
…tations
  • Loading branch information
Adamantcheese committed Feb 27, 2020
1 parent 26902a1 commit 8f60f89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public long open(DataSpec dataSpec)
}

transferStarted(dataSpec);

opened = true;
return bytesRemaining;
}

Expand All @@ -345,7 +345,7 @@ public int read(byte[] buffer, int offset, int readLength)
throws IOException {
if (readLength == 0) {
return 0;
} else if (bytesRemaining() == 0) {
} else if (bytesRemaining() == 0 || dataSource == null) {
return C.RESULT_END_OF_INPUT;
}

Expand Down Expand Up @@ -389,18 +389,22 @@ public void cacheComplete() {

BackgroundUtils.runOnMainThread(() -> {
for (Callback c : listeners) {
if (c != null) c.dataSourceAddedFile(innerFile);
c.dataSourceAddedFile(innerFile);
}

listeners.clear();
partialFileCache.clearListeners();
clearListeners();
});
}

public void addListener(Callback c) {
if (c != null) listeners.add(c);
}

public void clearListeners() {
listeners.clear();
partialFileCache.clearListeners();
}

@Nullable
@Override
public Uri getUri() {
Expand All @@ -411,9 +415,11 @@ public Uri getUri() {
public void close()
throws IOException {
Logger.i(TAG, "close");
clearListeners();
try {
if (dataSource != null) {
dataSource.close();
dataSource = null;
}
} finally {
if (opened) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ class WebmStreamingSource(
val fileCacheSource = WebmStreamingDataSource(uri, rawFile, fileManager)

fileCacheSource.addListener { file ->
run {
BackgroundUtils.ensureMainThread()
cacheHandler.fileWasAdded(file.length())
}
BackgroundUtils.ensureMainThread()
cacheHandler.fileWasAdded(file.length())
}

if (alreadyExists
Expand Down

0 comments on commit 8f60f89

Please sign in to comment.