forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[video_player_android] Add RTSP support (flutter#7081)
Add RTSP support to `DataSourceType.network` videos on Android platform. I'm using this patch on my projects and it works well, but I need some feedback if the approach used is correct. If so, I will continue writing the tests. This PR implements the Android part of this feature request: flutter#18061 . I added a RTSP tab on the example app: https://github.com/flutter/packages/assets/7874200/9f0addb1-f6bb-4ec6-b8ad-e889f7d8b154
- Loading branch information
Showing
10 changed files
with
171 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ Anton Borries <[email protected]> | |
Alex Li <[email protected]> | ||
Rahul Raj <[email protected]> | ||
Márton Matuz <[email protected]> | ||
André Sousa <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.6.0 | ||
|
||
* Adds RTSP support. | ||
|
||
## 2.5.4 | ||
|
||
* Updates Media3-ExoPlayer to 1.4.0. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...o_player_android/android/src/main/java/io/flutter/plugins/videoplayer/RtspVideoAsset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.videoplayer; | ||
|
||
import android.content.Context; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.OptIn; | ||
import androidx.media3.common.MediaItem; | ||
import androidx.media3.common.util.UnstableApi; | ||
import androidx.media3.exoplayer.rtsp.RtspMediaSource; | ||
import androidx.media3.exoplayer.source.MediaSource; | ||
|
||
final class RtspVideoAsset extends VideoAsset { | ||
RtspVideoAsset(@NonNull String assetUrl) { | ||
super(assetUrl); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
MediaItem getMediaItem() { | ||
return new MediaItem.Builder().setUri(assetUrl).build(); | ||
} | ||
|
||
// TODO: Migrate to stable API, see https://github.com/flutter/flutter/issues/147039. | ||
@OptIn(markerClass = UnstableApi.class) | ||
@Override | ||
MediaSource.Factory getMediaSourceFactory(Context context) { | ||
return new RtspMediaSource.Factory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,8 +69,8 @@ public void remoteVideoByDefaultSetsUserAgentAndCrossProtocolRedirects() { | |
|
||
DefaultHttpDataSource.Factory mockFactory = mockHttpFactory(); | ||
|
||
// Cast to RemoteVideoAsset to call a testing-only method to intercept calls. | ||
((RemoteVideoAsset) asset) | ||
// Cast to HttpVideoAsset to call a testing-only method to intercept calls. | ||
((HttpVideoAsset) asset) | ||
.getMediaSourceFactory(ApplicationProvider.getApplicationContext(), mockFactory); | ||
|
||
verify(mockFactory).setUserAgent("ExoPlayer"); | ||
|
@@ -89,8 +89,8 @@ public void remoteVideoOverridesUserAgentIfProvided() { | |
|
||
DefaultHttpDataSource.Factory mockFactory = mockHttpFactory(); | ||
|
||
// Cast to RemoteVideoAsset to call a testing-only method to intercept calls. | ||
((RemoteVideoAsset) asset) | ||
// Cast to HttpVideoAsset to call a testing-only method to intercept calls. | ||
((HttpVideoAsset) asset) | ||
.getMediaSourceFactory(ApplicationProvider.getApplicationContext(), mockFactory); | ||
|
||
verify(mockFactory).setUserAgent("FantasticalVideoBot"); | ||
|
@@ -127,12 +127,28 @@ public void remoteVideoSetsAdditionalHttpHeadersIfProvided() { | |
|
||
DefaultHttpDataSource.Factory mockFactory = mockHttpFactory(); | ||
|
||
// Cast to RemoteVideoAsset to call a testing-only method to intercept calls. | ||
((RemoteVideoAsset) asset) | ||
// Cast to HttpVideoAsset to call a testing-only method to intercept calls. | ||
((HttpVideoAsset) asset) | ||
.getMediaSourceFactory(ApplicationProvider.getApplicationContext(), mockFactory); | ||
|
||
verify(mockFactory).setUserAgent("ExoPlayer"); | ||
verify(mockFactory).setAllowCrossProtocolRedirects(true); | ||
verify(mockFactory).setDefaultRequestProperties(headers); | ||
} | ||
|
||
@Test | ||
public void rtspVideoRequiresRtspUrl() { | ||
assertThrows( | ||
IllegalArgumentException.class, () -> VideoAsset.fromRtspUrl("https://not.rtsp/video.mp4")); | ||
} | ||
|
||
@Test | ||
public void rtspVideoCreatesMediaItem() { | ||
VideoAsset asset = VideoAsset.fromRtspUrl("rtsp://test:[email protected]/stream"); | ||
MediaItem mediaItem = asset.getMediaItem(); | ||
|
||
assert mediaItem.localConfiguration != null; | ||
assertEquals( | ||
mediaItem.localConfiguration.uri, Uri.parse("rtsp://test:[email protected]/stream")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters