0

Javascript インターフェイスを使用して別のクラスからプロシージャを呼び出すことに関して問題があります。問題は、ExoPlayer クラスから iniExoPlayer を呼び出すと、NullPointerException が発生することです...

ログを見ると、iniExoPlayer プロシージャに送信されたコンテキストが null であるためであることがわかりました...

ExoPlayer クラスで使用しようとしcontext.getActivity()ましたが、まだエラーが発生しています...

どうすればこれを解決できますか?

WebAppInterface.java

    public class WebAppInterface{ 
    public Context context;

    public  WebAppInterface(Context context){
       this.context = context;
    }


    ExoPlayer exoPlayer = new ExoPlayer();



    @JavascriptInterface
    public void show(String vidio){

        exoPlayer.iniExoPlayer(vidio);
    }

ExoPlayer.java

    public class ExoPlayer extends AppCompatActivity{
    private PlayerView playerView;
    private SimpleExoPlayer simpleExoPlayer;
    public static String url;
    public Context context;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_player);

    }


    public void iniExoPlayer(String url){
        Log.d("owo",url);
        simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context);
        playerView = findViewById(R.id.video_player);
        playerView.setPlayer(simpleExoPlayer);
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context,"appname"));
        MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url));
        simpleExoPlayer.prepare(videoSource);
        simpleExoPlayer.setPlayWhenReady(true);

    }

ログキャット

W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.<init>(MediaCodecVideoRenderer.java:226)
W/System.err:     at com.google.android.exoplayer2.DefaultRenderersFactory.buildVideoRenderers(DefaultRenderersFactory.java:211)
        at com.google.android.exoplayer2.DefaultRenderersFactory.createRenderers(DefaultRenderersFactory.java:180)
        at com.google.android.exoplayer2.SimpleExoPlayer.<init>(SimpleExoPlayer.java:213)
        at com.google.android.exoplayer2.SimpleExoPlayer.<init>(SimpleExoPlayer.java:166)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:386)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:352)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:320)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:214)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:180)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:151)
        at com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance(ExoPlayerFactory.java:141)
        at adnankhairi.webviewer2.ExoPlayer.iniExoPlayer(ExoPlayer.java:37)
        at adnankhairi.webviewer2.WebAppInterface.show(WebAppInterface.java:29)
        at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err:     at android.os.MessageQueue.next(MessageQueue.java:328)
        at android.os.Looper.loop(Looper.java:164)
        at android.os.HandlerThread.run(HandlerThread.java:61)
I/chromium: [INFO:CONSOLE(55)] "Uncaught Error: Java exception was raised during method invocation", source:  (55)

4

0 に答える 0