Simple Multicast Video Player in Java

Viewed 48

PROBLEM: I've put together a some code based on solutions I've found on the net, but when I run it, I get:

NullPointerException - Attempt to invoke virtual method 'java.lang.Object.android.content.Context.getSystemService(java.lang.Class)' on a null object reference

I get this exception when I run the final line, mMediaPlayer.play();

Checking whether these relevant objects (mLibVLC, mMediaPlayer, mMedia) are null when I'm using them suggests they are not.

When I put the RTP address directly into the VLC app on the tablet, the video plays just fine.

BACKGROUND: I'm trying to write a plugin for Android Team Awareness Kit (ATAK) that will allow me to stream and control a PTZ camera from an Android tablet, plugged in through an Ethernet adapter.

ATAK Plugin SDK - https://github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/releases

Because I'm working with an existing SDK, I'm limited to what I can use. I believe I have to use a minSdkVersion = 21, and a compileSdkVersion = 26 in my build.gradle. I have tried changing them to newer versions (e.g. compileSdkVersion = 28) but quickly fall into a vortex of other errors.

AIM: I'm trying to play a multicast UDP video stream live in my plugin. To do this, I'm using libvlc and trying to tie it into the existing plugin structure.

CODE: Relevant Imports

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
import org.videolan.libvlc.media.VideoView;
import org.videolan.libvlc.util.VLCVideoLayout;

Definitions

private VLCVideoLayout VideoFrame;
private LibVLC mLibVLC = null;
private org.videolan.libvlc.MediaPlayer mMediaPlayer;

Relevant Video Playing Code

VideoFrame = myFirstFragment.findViewById(R.id.videoViewFrame);
String Video_URL = "rtsp://*****************";

mLibVLC = new LibVLC(this.pluginContext);
mMediaPlayer = new MediaPlayer(mLibVLC);
mMediaPlayer.attachViews(VideoFrame, null, false, false);

Media media = new Media(mLibVLC, Video_URL);
media.setHWDecoderEnabled(true, false);
mMediaPlayer.setMedia(media);
media.release();

mMediaPlayer.play();

In my frame constructor .XML

<org.videolan.libvlc.util.VLCVideoLayout
    android:id="@+id/videoViewFrame"
    android:layout_width="155dp"
    android:layout_height="94dp"
    android:fitsSystemWindows="true"
    android:visibility="visible"
    tools:visibility="visible" />

Added to my build.gradle dependencies

implementation files('C:\\******\\libvlc-all-4.0.0-eap1.aar')

OTHER THINGS I HAVE TRIED: I've also tried implementing an alternate that I found online, but ATAK refuses to load the plugin with the setVideoURI line, which is obviously a pretty important line. I get a popup saying my plugin is incompatible.

Uri uri = Uri.parse("rtsp://***********");
org.videolan.libvlc.media.VideoView mVideoView = (VideoView) myFirstFragment.findViewById(R.id.videoViewFrame);
VideoFrame.setMediaController(new MediaController(this.pluginContext));
VideoFrame.setVideoURI(uri);
VideoFrame.requestFocus();
VideoFrame.start();

In this case, I also changed the frame type in my frame constructor .XML from VLCVideoLayout to org.videolan.libvlc.media.VideoView

I've also tried putting the entire code into an AppCompatActivity (which is how the original example was built) however had great trouble figuring out how to get the VideoView/VLCVideoLayout frame into the activity to bind the video to, and also determining how to get the activity to actually run. Also, this solution just seemed to be so much more complicated than I figure it should be.

When I get this running through whatever method, I'll bind it to a start and stop button.

0 Answers
Related