Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation scaling mode dynamic android and ios #270

Merged
merged 9 commits into from
Oct 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bitmovin.player.reactnative
import android.util.Log
import com.bitmovin.analytics.api.DefaultMetadata
import com.bitmovin.player.api.Player
import com.bitmovin.player.api.ui.ScalingMode
import com.bitmovin.player.api.analytics.create
import com.bitmovin.player.api.event.PlayerEvent
import com.bitmovin.player.reactnative.converter.JsonConverter
Expand Down Expand Up @@ -412,6 +413,28 @@ class PlayerModule(private val context: ReactApplicationContext) : ReactContextB
}
}

/**
* Set `nativeId`'s player.
* @param nativeId Target player Id.
* @param scaling Mode to change scale.
* @param promise JS promise object.
*/
@ReactMethod
fun setScalingMode(nativeId: NativeId, scalingMode: String, promise: Promise) {
uiManager()?.addUIBlock {
if (scalingMode == "Zoom") {
players[nativeId]?.config?.styleConfig?.scalingMode = ScalingMode.Zoom
}
if (scalingMode == "Fit") {
players[nativeId]?.config?.styleConfig?.scalingMode = ScalingMode.Fit
}
if (scalingMode == "Stretch") {
players[nativeId]?.config?.styleConfig?.scalingMode = ScalingMode.Stretch
}
promise.resolve(null)
}
}

/**
* Schedules an `AdItem` in the `nativeId`'s associated player.
* @param nativeId Target player id.
Expand Down
9 changes: 8 additions & 1 deletion src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NativeInstance, { NativeInstanceConfig } from './nativeInstance';
import { Source, SourceConfig } from './source';
import { AudioTrack } from './audioTrack';
import { SubtitleTrack } from './subtitleTrack';
import { StyleConfig } from './styleConfig';
import { ScalingMode, StyleConfig } from './styleConfig';
import { TweaksConfig } from './tweaksConfig';
import { AdaptationConfig } from './adaptationConfig';
import { OfflineContentManager, OfflineSourceOptions } from './offline';
Expand Down Expand Up @@ -429,6 +429,13 @@ export class Player extends NativeInstance<PlayerConfig> {
return PlayerModule.setSubtitleTrack(this.nativeId, trackIdentifier);
};

/**
* Sets the scaling Mode.
*/
setScalingMode = async (scalingMode: ScalingMode): Promise<void> => {
return PlayerModule.setScalingMode(this.nativeId, scalingMode);
};

/**
* Dynamically schedules the `adItem` for playback.
* Has no effect if there is no active playback session.
Expand Down