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

Android: app crashes #6

Open
JumBay opened this issue Dec 12, 2024 · 8 comments
Open

Android: app crashes #6

JumBay opened this issue Dec 12, 2024 · 8 comments
Assignees

Comments

@JumBay
Copy link

JumBay commented Dec 12, 2024

Hi,

Thanks for the plugin.

I did a try on android an got the error:

Serious error executing plugin
                                                                                                    java.lang.reflect.InvocationTargetException
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
                                                                                                    	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:821)
                                                                                                    	at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0)
                                                                                                    	at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:224)
                                                                                                    	at android.os.Looper.loop(Looper.java:318)
                                                                                                    	at android.os.HandlerThread.run(HandlerThread.java:67)
                                                                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.getcapacitor.JSObject com.getcapacitor.JSObject.getJSObject(java.lang.String)' on a null object reference
                                                                                                    	at dev.eduardoroth.mediaplayer.MediaPlayerPlugin.create(MediaPlayerPlugin.java:58)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 
                                                                                                    	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:821) 
                                                                                                    	at com.getcapacitor.Bridge.$r8$lambda$FNYM7cvgeBk0k8YXQH7M96Mrf-c(Unknown Source:0) 
                                                                                                    	at com.getcapacitor.Bridge$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) 
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:224) 
                                                                                                    	at android.os.Looper.loop(Looper.java:318) 
                                                                                                    	at android.os.HandlerThread.run(HandlerThread.java:67) 

The code I use :

 const playerId = Math.random().toString(36).substring(2, 15);

    await MediaPlayer.create({
      playerId,
      url: 'https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4',
      // extra: {
      //   title,
      //   // poster,
      //   autoPlayWhenReady: true,
      //   showControls: true,
      //   rate: 1.0,
      // },
      // ios: {
      //   enablePiP: true,
      //   enableBackgroundPlay: true,
      //   openInFullscreen: true,
      //   fullscreenOnLandscape: true,
      // },
      // android: {
      //   enablePiP: false,
      //   enableBackgroundPlay: false,
      //   openInFullscreen: true,
      //   fullscreenOnLandscape: true,
      // },
    });
    ```
@eduardoRoth
Copy link
Owner

@JumBay thank you for trying my plugin! This error is fixed on version 2.0.5

@eduardoRoth eduardoRoth self-assigned this Dec 12, 2024
@JumBay
Copy link
Author

JumBay commented Dec 13, 2024

Thx, but it still crashes:

FATAL EXCEPTION: main
                                                                                                    Process: app.wako, PID: 10333
                                                                                                    java.lang.IllegalArgumentException: No view found for id 0x7f0a000c (app.wako:id/MediaPlayerFragmentContainerView) for fragment MediaPlayerContainer{e5cdb60} (44a34cbd-cbe9-4c0e-ae50-c0ffbaa7887d id=0x7f0a000c tag=rwfyig0iilo)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:547)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
                                                                                                    	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
                                                                                                    	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1839)
                                                                                                    	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
                                                                                                    	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:224)
                                                                                                    	at android.os.Looper.loop(Looper.java:318)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8772)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
                                                                                                    	

Moreover I had to set default value for top, start, width... otherwise it throw a null pointer exception

@eduardoRoth
Copy link
Owner

@JumBay Sorry, for the delay, v2.0.6 should fix these issues.

@eduardoRoth
Copy link
Owner

@JumBay , please let me know if the issue is fixed.

@JumBay
Copy link
Author

JumBay commented Dec 23, 2024

Thx I've been busy lately, I'll check it soon

@eduardoRoth
Copy link
Owner

@JumBay , I have made more changes since v2.0.6 you should give a try and let me know if everything is working.

@JumBay
Copy link
Author

JumBay commented Jan 21, 2025

Hi,

Sorry for the delay.

So I've been able to try the latest version (3.1.0) on my app wako.app but it still crashes:

FATAL EXCEPTION: main (Ask Gemini)
                                                                                                    Process: app.wako, PID: 3332
                                                                                                    java.lang.IllegalArgumentException: No view found for id 0x7f0a000a (app.wako:id/MediaPlayerFragmentContainerView) for fragment MediaPlayerContainer{4c69dd1} (dd4904c0-4701-40cf-8652-04260c1148a5 id=0x7f0a000a tag=fullscreen)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:547)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
                                                                                                    	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
                                                                                                    	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1839)
                                                                                                    	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
                                                                                                    	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7839)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Here is the code I use:

import { MediaPlayer, MediaPlayerOptions } from '@eduardoroth/media-player';
import { OpenMedia, VideoPlayerEvents } from '@wako-app/mobile-sdk';
import { Subject } from 'rxjs';

export class WakoVideoPlayerExtendedV2Service {
  static async openVideoUrl({
    videoUrl,
    startAt = 0,
    openMedia,
    title,
    poster,
  }: {
    videoUrl: string;
    startAt?: number;
    openMedia?: OpenMedia;
    title?: string;
    poster?: string;
    subtitle?: string;
  }): Promise<VideoPlayerEvents> {
    const playerId = 'fullscreen';

    const options: MediaPlayerOptions = {
      playerId,
      url: `https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4`,
      placement: {
        videoOrientation: 'HORIZONTAL',
      },
      extra: {
        title: 'Test Title',
        subtitle: 'Test Subtitle',
        poster: 'https://image.tmdb.org/t/p/w342/nw2jRlCbBapEsRAMtsLONBbqXxp.jpg',
        autoPlayWhenReady: false,
        showControls: true,
      },
      ios: {
        enablePiP: false,
        fullscreenOnLandscape: true,
      },
      android: {
        enablePiP: false,
        fullscreenOnLandscape: true,
      },
    };

    console.log('options', options);

    // Initialize player with MediaPlayer plugin
    await MediaPlayer.create(options);

    const listeners: any[] = [];
    let duration: number;
    let currentTime: number;
    const timeSubject = new Subject<{ currentTime: number; totalDuration: number }>();

    // Setup keyboard controls
    const keyupHandler = async (e: KeyboardEvent) => {
      let handled = false;

      switch (e.key) {
        case 'MediaFastForward':
        case 'ArrowRight': {
          handled = true;
          const result = await MediaPlayer.getCurrentTime({ playerId });
          MediaPlayer.setCurrentTime({ playerId, time: result.value + 10 });
          break;
        }
        case 'MediaRewind':
        case 'ArrowLeft': {
          handled = true;
          const result = await MediaPlayer.getCurrentTime({ playerId });
          MediaPlayer.setCurrentTime({ playerId, time: Math.max(0, result.value - 10) });
          break;
        }
        case 'MediaPlay':
          handled = true;
          MediaPlayer.play({ playerId });
          break;

        case 'MediaPause':
          handled = true;
          MediaPlayer.pause({ playerId });
          break;

        case 'MediaPlayPause':
          handled = true;
          const isPlaying = await MediaPlayer.isPlaying({ playerId });
          if (isPlaying.value) {
            MediaPlayer.pause({ playerId });
          } else {
            MediaPlayer.play({ playerId });
          }
          break;
      }

      if (handled) {
        e.preventDefault();
        e.stopPropagation();
      }
    };

    document.addEventListener('keyup', keyupHandler);

    // Setup time update interval
    const timeInterval = setInterval(async () => {
      try {
        if (!duration) {
          const durationResult = await MediaPlayer.getDuration({ playerId });
          duration = durationResult.value;
        }
        const currentTimeResult = await MediaPlayer.getCurrentTime({ playerId });
        currentTime = currentTimeResult.value;

        timeSubject.next({ currentTime, totalDuration: duration });
      } catch (error) {
        timeSubject.error(error);
      }
    }, 5000);

    // Cleanup function
    const cleanup = () => {
      document.removeEventListener('keyup', keyupHandler);
      clearInterval(timeInterval);
      timeSubject.complete();
      listeners.forEach((listener) => {
        if (listener?.remove) {
          listener.remove();
        }
      });
      MediaPlayer.remove({ playerId });
    };

    const readyListener = await MediaPlayer.addListener('MediaPlayer:Ready', async () => {
      debugger;
      if (startAt) {
        await MediaPlayer.setCurrentTime({ playerId, time: startAt });
      }
      await MediaPlayer.play({ playerId });
      readyListener.remove();
    });
    listeners.push(readyListener);

    // Play video
    //

    return {
      onExit: new Promise((resolve) => {
        const exitListener = MediaPlayer.addListener('MediaPlayer:Removed', () => {
          cleanup();
          resolve({ currentTime, percent: Math.round((currentTime / duration) * 100), openMedia });
        });

        const endedListener = MediaPlayer.addListener('MediaPlayer:Ended', () => {
          cleanup();
          resolve({ currentTime, percent: Math.round((currentTime / duration) * 100), openMedia });
        });

        listeners.push(exitListener, endedListener);
      }),
      onCurrentTime: timeSubject.asObservable(),
      playerId,
    } as VideoPlayerEvents;
  }

  static closePlayer() {
    MediaPlayer.removeAll();
  }
}

@eduardoRoth
Copy link
Owner

@JumBay this issue is fixed in version v3.1.4

You also need to be on Gradle version 8.7, so update your gradle-wrapper.properties file to have the value of distributionUrl like this:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants