Skip to content

Commit 37530ab

Browse files
committed
Fix Android share issue
1 parent 208820d commit 37530ab

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

example/VideoLayerDemo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function VideoLayerDemo({ onBack }: VideoLayerDemoProps) {
3131
<CLDVideoLayer
3232
cldVideo={createMyVideoObject()}
3333
onBack={onBack}
34-
onShare={handleShare}
34+
// onShare={handleShare}
3535
// Example: Position back button in top-left (NW) and share button in top-right (NE)
3636
backButtonPosition={ButtonPosition.NW}
3737
shareButtonPosition={ButtonPosition.NE}

example/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ module.exports = function(api) {
22
api.cache(true);
33
return {
44
presets: ['babel-preset-expo'],
5+
plugins: [
6+
['@babel/plugin-transform-class-properties', { loose: true }],
7+
['@babel/plugin-transform-private-methods', { loose: true }],
8+
['@babel/plugin-transform-private-property-in-object', { loose: true }],
9+
],
510
};
611
};

src/AdvancedVideo.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface AdvancedVideoRef {
3434
pauseAsync: () => Promise<void>;
3535
setIsMutedAsync: (isMuted: boolean) => Promise<void>;
3636
setPositionAsync: (positionMillis: number) => Promise<void>;
37+
setStatusAsync: (status: any) => Promise<void>;
3738
}
3839

3940
class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
@@ -206,7 +207,8 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
206207
public playAsync = async () => {
207208
if (this.videoRef.current) {
208209
try {
209-
await this.videoRef.current.playAsync();
210+
// expo-av uses setStatusAsync for playback control
211+
await this.videoRef.current.setStatusAsync({ shouldPlay: true });
210212
} catch (error) {
211213
console.warn('Failed to play video:', error);
212214
}
@@ -216,7 +218,8 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
216218
public pauseAsync = async () => {
217219
if (this.videoRef.current) {
218220
try {
219-
await this.videoRef.current.pauseAsync();
221+
// expo-av uses setStatusAsync for playback control
222+
await this.videoRef.current.setStatusAsync({ shouldPlay: false });
220223
} catch (error) {
221224
console.warn('Failed to pause video:', error);
222225
}
@@ -226,7 +229,8 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
226229
public setIsMutedAsync = async (isMuted: boolean) => {
227230
if (this.videoRef.current) {
228231
try {
229-
await this.videoRef.current.setIsMutedAsync(isMuted);
232+
// expo-av uses setStatusAsync for muting
233+
await this.videoRef.current.setStatusAsync({ isMuted });
230234
} catch (error) {
231235
console.warn('Failed to set muted state:', error);
232236
}
@@ -236,13 +240,25 @@ class AdvancedVideo extends Component<AdvancedVideoProps, AdvancedVideoState> {
236240
public setPositionAsync = async (positionMillis: number) => {
237241
if (this.videoRef.current) {
238242
try {
239-
await this.videoRef.current.setPositionAsync(positionMillis);
243+
// expo-av uses setStatusAsync for seeking
244+
await this.videoRef.current.setStatusAsync({ positionMillis });
240245
} catch (error) {
241246
console.warn('Failed to set position:', error);
242247
}
243248
}
244249
};
245250

251+
public setStatusAsync = async (status: any) => {
252+
if (this.videoRef.current) {
253+
try {
254+
// Forward to underlying video component
255+
await this.videoRef.current.setStatusAsync(status);
256+
} catch (error) {
257+
console.warn('Failed to set status:', error);
258+
}
259+
}
260+
};
261+
246262
render() {
247263
const videoUri = this.getVideoUri();
248264
console.log('AdvancedVideo - Render:', {

src/adapters/ExpoAVVideoAdapter.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export class ExpoAVVideoAdapter implements VideoPlayerAdapter {
4141
const { Video } = this.expoAVModule;
4242

4343
return React.createElement(Video, {
44-
ref,
44+
ref: (videoInstance: any) => {
45+
if (ref && typeof ref === 'object' && 'current' in ref) {
46+
ref.current = videoInstance;
47+
}
48+
},
4549
source: { uri: props.videoUri },
4650
style: props.style,
4751
useNativeControls: false,

src/widgets/video/layer/CLDVideoLayer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
8686
validSeekPosition >= 0 &&
8787
validSeekPosition < this.state.status.durationMillis) {
8888

89-
this.videoRef.current.setPositionAsync(validSeekPosition).catch((error) => {
89+
this.videoRef.current.setStatusAsync({ positionMillis: validSeekPosition }).catch((error: any) => {
9090
console.warn('Seek failed:', error);
9191
this.setState({
9292
isSeeking: false,
@@ -266,9 +266,9 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
266266
if (this.videoRef.current) {
267267
try {
268268
if (this.state.status?.isPlaying) {
269-
await this.videoRef.current.pauseAsync();
269+
await this.videoRef.current.setStatusAsync({ shouldPlay: false });
270270
} else {
271-
await this.videoRef.current.playAsync();
271+
await this.videoRef.current.setStatusAsync({ shouldPlay: true });
272272
}
273273
} catch (error) {
274274
console.warn('Failed to toggle play/pause:', error);

src/widgets/video/layer/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const useVideoSeeking = () => {
142142
validSeekPosition < status.durationMillis) {
143143

144144
lastSeekTime.current = now;
145-
videoRef.current.setPositionAsync(validSeekPosition).catch((error: any) => {
145+
videoRef.current.setStatusAsync({ positionMillis: validSeekPosition }).catch((error: any) => {
146146
console.warn('Seek failed:', error);
147147
resolve({
148148
isSeeking: false,

src/widgets/video/layer/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Share } from 'react-native';
1+
import { Share, Platform } from 'react-native';
22
import type { CloudinaryVideo } from '@cloudinary/url-gen';
33

44
/**
@@ -18,7 +18,7 @@ export const handleDefaultShare = async (cldVideo: CloudinaryVideo): Promise<voi
1818
try {
1919
const videoUrl = cldVideo.toURL();
2020
await Share.share({
21-
message: '',
21+
message: Platform.OS === 'ios' ? '' : videoUrl,
2222
url: videoUrl,
2323
});
2424
} catch (error) {

0 commit comments

Comments
 (0)