SkipAd handling pigeon, android, ios, flutter
This commit is contained in:
parent
b62174fba7
commit
b22a3df404
9 changed files with 82 additions and 1 deletions
|
|
@ -491,6 +491,7 @@ public class PlatformBridgeApis {
|
||||||
void pause();
|
void pause();
|
||||||
void stop();
|
void stop();
|
||||||
void showTracksChooserDialog();
|
void showTracksChooserDialog();
|
||||||
|
void skipAd();
|
||||||
|
|
||||||
/** The codec used by CastHostApi. */
|
/** The codec used by CastHostApi. */
|
||||||
static MessageCodec<Object> getCodec() {
|
static MessageCodec<Object> getCodec() {
|
||||||
|
|
@ -704,6 +705,25 @@ public class PlatformBridgeApis {
|
||||||
channel.setMessageHandler(null);
|
channel.setMessageHandler(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
BasicMessageChannel<Object> channel =
|
||||||
|
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.skipAd", getCodec());
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler((message, reply) -> {
|
||||||
|
Map<String, Object> wrapped = new HashMap<>();
|
||||||
|
try {
|
||||||
|
api.skipAd();
|
||||||
|
wrapped.put("result", null);
|
||||||
|
}
|
||||||
|
catch (Error | RuntimeException exception) {
|
||||||
|
wrapped.put("error", wrapError(exception));
|
||||||
|
}
|
||||||
|
reply.reply(wrapped);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
channel.setMessageHandler(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static class CastFlutterApiCodec extends StandardMessageCodec {
|
private static class CastFlutterApiCodec extends StandardMessageCodec {
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,11 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
|
||||||
.show(activity.supportFragmentManager, "FlutterCastFrameworkTracksChooserDialog")
|
.show(activity.supportFragmentManager, "FlutterCastFrameworkTracksChooserDialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun skipAd() {
|
||||||
|
val remoteMediaClient: RemoteMediaClient = remoteMediaClient ?: return
|
||||||
|
remoteMediaClient.skipAd()
|
||||||
|
}
|
||||||
|
|
||||||
override fun setMute(muted: Boolean?) {
|
override fun setMute(muted: Boolean?) {
|
||||||
if (muted == null) return
|
if (muted == null) return
|
||||||
val castSession = mCastSession ?: return
|
val castSession = mCastSession ?: return
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
|
||||||
- (void)pauseWithError:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)pauseWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
|
- (void)skipAdWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
||||||
|
|
|
||||||
|
|
@ -540,6 +540,24 @@ void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastH
|
||||||
[channel setMessageHandler:nil];
|
[channel setMessageHandler:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
FlutterBasicMessageChannel *channel =
|
||||||
|
[FlutterBasicMessageChannel
|
||||||
|
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.skipAd"
|
||||||
|
binaryMessenger:binaryMessenger
|
||||||
|
codec:CastHostApiGetCodec()];
|
||||||
|
if (api) {
|
||||||
|
NSCAssert([api respondsToSelector:@selector(skipAdWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(skipAdWithError:)", api);
|
||||||
|
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||||
|
FlutterError *error;
|
||||||
|
[api skipAdWithError:&error];
|
||||||
|
callback(wrapResult(nil, error));
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[channel setMessageHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,9 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
|
||||||
print("showTracksChooserDialog: unsupported feature")
|
print("showTracksChooserDialog: unsupported feature")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func skipAdWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||||
|
remoteMediaClient?.skipAd()
|
||||||
|
}
|
||||||
// MARK: - GCKSessionManagerListener
|
// MARK: - GCKSessionManagerListener
|
||||||
|
|
||||||
// onSessionSuspended
|
// onSessionSuspended
|
||||||
|
|
|
||||||
|
|
@ -585,6 +585,29 @@ class CastHostApi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> skipAd() async {
|
||||||
|
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||||
|
'dev.flutter.pigeon.CastHostApi.skipAd', codec, binaryMessenger: _binaryMessenger);
|
||||||
|
final Map<Object?, Object?>? replyMap =
|
||||||
|
await channel.send(null) as Map<Object?, Object?>?;
|
||||||
|
if (replyMap == null) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: 'channel-error',
|
||||||
|
message: 'Unable to establish connection on channel.',
|
||||||
|
details: null,
|
||||||
|
);
|
||||||
|
} else if (replyMap['error'] != null) {
|
||||||
|
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
|
||||||
|
throw PlatformException(
|
||||||
|
code: (error['code'] as String?)!,
|
||||||
|
message: error['message'] as String?,
|
||||||
|
details: error['details'],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CastFlutterApiCodec extends StandardMessageCodec {
|
class _CastFlutterApiCodec extends StandardMessageCodec {
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,11 @@ class RemoteMediaClient {
|
||||||
_hostApi.showTracksChooserDialog();
|
_hostApi.showTracksChooserDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Skips the playing ad.
|
||||||
|
void skipAd() {
|
||||||
|
_hostApi.skipAd();
|
||||||
|
}
|
||||||
|
|
||||||
/// Internal method that shouldn't be visible
|
/// Internal method that shouldn't be visible
|
||||||
@internal
|
@internal
|
||||||
void dispatchPlayerStateUpdate(PlayerState playerState) {
|
void dispatchPlayerStateUpdate(PlayerState playerState) {
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,11 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
.updateProgress(progressMs, durationMs, whenSkippableMs);
|
.updateProgress(progressMs, durationMs, whenSkippableMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onSkipAd() {
|
||||||
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
|
sessionManager.remoteMediaClient.skipAd();
|
||||||
|
}
|
||||||
|
|
||||||
Widget _getDecoratedToolbar(MediaInfo? mediaInfo) {
|
Widget _getDecoratedToolbar(MediaInfo? mediaInfo) {
|
||||||
// Title and subtitle can't be retrieved at the moment
|
// Title and subtitle can't be retrieved at the moment
|
||||||
// final title = mediaInfo?.mediaMetadata?.strings[MediaMetadataKey.title]
|
// final title = mediaInfo?.mediaMetadata?.strings[MediaMetadataKey.title]
|
||||||
|
|
@ -221,7 +226,7 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
controller: widget.adSkipBoxController,
|
controller: widget.adSkipBoxController,
|
||||||
skipAdButtonText: widget.skipAdButtonText,
|
skipAdButtonText: widget.skipAdButtonText,
|
||||||
skipAdTimerText: widget.skipAdTimerText,
|
skipAdTimerText: widget.skipAdTimerText,
|
||||||
onSkipPressed: () {/* TODO: skip ad */},
|
onSkipPressed: _onSkipAd,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,7 @@ abstract class CastHostApi {
|
||||||
void pause();
|
void pause();
|
||||||
void stop();
|
void stop();
|
||||||
void showTracksChooserDialog();
|
void showTracksChooserDialog();
|
||||||
|
void skipAd();
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue