Skip to content

Commit

Permalink
move player to new class and add player stop/release
Browse files Browse the repository at this point in the history
  • Loading branch information
bi119aTe5hXk committed Jun 7, 2023
1 parent b465277 commit 11b11b0
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 258 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ android {
dependencies {

implementation 'androidx.leanback:leanback:1.0.0'
implementation 'org.videolan.android:libvlc-all:4.0.0-eap11'
implementation 'org.videolan.android:libvlc-all:3.6.0-eap8'
// implementation 'com.google.android.exoplayer:exoplayer:2.18.7'
// implementation 'com.google.android.exoplayer:exoplayer-rtsp:2.18.7'
implementation 'androidx.appcompat:appcompat:1.4.1'
}
76 changes: 76 additions & 0 deletions app/src/main/java/net/bi119ate5hxk/rtspplayer/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.bi119ate5hxk.rtspplayer;
import android.content.Context;

import android.net.Uri;
import android.util.Log;
import androidx.annotation.IdRes;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
import org.videolan.libvlc.util.VLCVideoLayout;
//import android.media.MediaPlayer;
//import com.google.android.exoplayer2.ExoPlayer;
//import com.google.android.exoplayer2.MediaItem;
//import com.google.android.exoplayer2.source.MediaSource;
//import com.google.android.exoplayer2.source.rtsp.RtspMediaSource;
//import com.google.android.exoplayer2.ui.StyledPlayerView;


public class Player {

//ExoPlayer player;
Media media;
MediaPlayer mediaPlayer;
LibVLC libVlc;

public Player(String url, VLCVideoLayout playerView, Context context) {
if (url.isEmpty()) {
Log.d("NO URL", "URL is empty");
return;
}
Log.d("URL", url);
libVlc = new LibVLC(context);
mediaPlayer = new MediaPlayer(libVlc);
mediaPlayer.attachViews(playerView, null, false, false);

media = new Media(libVlc, Uri.parse(url));
media.setHWDecoderEnabled(true, false);
//media.addOption(":network-caching=600");
media.addOption(":no-audio");
media.addOption(":quiet");
mediaPlayer.setMedia(media);
media.release();
mediaPlayer.play();

// MediaSource mediaSource =
// new RtspMediaSource.Factory()
// .createMediaSource(MediaItem.fromUri(url));
// player = new ExoPlayer.Builder(context)
// .setMediaSourceFactory(new RtspMediaSource.Factory().setDebugLoggingEnabled(true))
// .build();
// playerView.setPlayer(player);
// player.setMediaSource(mediaSource);
// player.prepare();
// player.play();


// Thread t = new Thread() {
// public void run() {
//
// }
// };
// t.start();
}


public void stopPlayer(){
mediaPlayer.stop();
mediaPlayer.getVLCVout().detachViews();
mediaPlayer.release();
libVlc.release();
Log.i("INFO","Play stopped");
}


}
114 changes: 36 additions & 78 deletions app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP16Activity.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
package net.bi119ate5hxk.rtspplayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.IdRes;
import java.util.ArrayList;
import androidx.appcompat.app.AppCompatActivity;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
//import com.google.android.exoplayer2.ui.StyledPlayerView;
import org.videolan.libvlc.util.VLCVideoLayout;

import java.util.ArrayList;

public class RTSP16Activity extends AppCompatActivity {

ArrayList<Player> pList =new ArrayList<>();
ArrayList<String> urlList = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rtsp16);
}

@Override
protected void onStart()
{
super.onStart();
Bundle extras = getIntent().getExtras();
ArrayList<String> urlList = new ArrayList<String>();
if (extras == null) {
Log.d("NO Extras","extras is null");
super.onBackPressed();
Expand All @@ -38,76 +29,43 @@ protected void onStart()
super.onBackPressed();
return;
}
if (urlList.size() >= 1){
createVLCPlayer(urlList.get(0),R.id.videoLayout1);
}
if (urlList.size() >= 2){
createVLCPlayer(urlList.get(1),R.id.videoLayout2);
}
if (urlList.size() >= 3) {
createVLCPlayer(urlList.get(2),R.id.videoLayout3);
}
if (urlList.size() >= 4) {
createVLCPlayer(urlList.get(3),R.id.videoLayout4);
}
if (urlList.size() >= 5) {
createVLCPlayer(urlList.get(4),R.id.videoLayout5);
}
if (urlList.size() >= 6) {
createVLCPlayer(urlList.get(5),R.id.videoLayout6);
}
if (urlList.size() >= 7) {
createVLCPlayer(urlList.get(6),R.id.videoLayout7);
}
if (urlList.size() >= 8) {
createVLCPlayer(urlList.get(7),R.id.videoLayout8);
}
if (urlList.size() >= 9) {
createVLCPlayer(urlList.get(8),R.id.videoLayout9);
}
if (urlList.size() >= 10){
createVLCPlayer(urlList.get(9),R.id.videoLayout10);
}
if (urlList.size() >= 11){
createVLCPlayer(urlList.get(10),R.id.videoLayout11);
}
if (urlList.size() >= 12){
createVLCPlayer(urlList.get(11),R.id.videoLayout12);
}
if (urlList.size() >= 13){
createVLCPlayer(urlList.get(12),R.id.videoLayout13);
}
if (urlList.size() >= 14){
createVLCPlayer(urlList.get(13),R.id.videoLayout14);
}
if (urlList.size() >= 15){
createVLCPlayer(urlList.get(14),R.id.videoLayout15);
}
if (urlList.size() >= 16){
createVLCPlayer(urlList.get(15),R.id.videoLayout16);
}

}

protected void createVLCPlayer(String url, @IdRes int viewId){
if (url.isEmpty()) {
Log.d("NO URL","URL is empty");
return;
}
Log.d("URL",url);
LibVLC libVlc = new LibVLC(this);
MediaPlayer mediaPlayer = new MediaPlayer(libVlc);
VLCVideoLayout videoLayout = findViewById(viewId);
ArrayList<VLCVideoLayout> viewsList =new ArrayList<>();
viewsList.add(findViewById(R.id.videoLayout1));
viewsList.add(findViewById(R.id.videoLayout2));
viewsList.add(findViewById(R.id.videoLayout3));
viewsList.add(findViewById(R.id.videoLayout4));
viewsList.add(findViewById(R.id.videoLayout5));
viewsList.add(findViewById(R.id.videoLayout6));
viewsList.add(findViewById(R.id.videoLayout7));
viewsList.add(findViewById(R.id.videoLayout8));
viewsList.add(findViewById(R.id.videoLayout9));
viewsList.add(findViewById(R.id.videoLayout10));
viewsList.add(findViewById(R.id.videoLayout11));
viewsList.add(findViewById(R.id.videoLayout12));
viewsList.add(findViewById(R.id.videoLayout13));
viewsList.add(findViewById(R.id.videoLayout14));
viewsList.add(findViewById(R.id.videoLayout15));
viewsList.add(findViewById(R.id.videoLayout16));

mediaPlayer.attachViews(videoLayout, null, false, false);
for (int i = 0; i < urlList.size(); i++) {
pList.add(new Player(urlList.get(i), viewsList.get(i), this));
}

Media media = new Media(libVlc, Uri.parse(url));
media.setHWDecoderEnabled(true, false);
media.addOption(":network-caching=600");
}

mediaPlayer.setMedia(media);
media.release();
mediaPlayer.play();
@Override
protected void onStart()
{
super.onStart();
}
@Override
public void onStop() {
super.onStop();
for (Player p : pList) {
p.stopPlayer();
}
}


Expand Down
42 changes: 14 additions & 28 deletions app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP1Activity.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package net.bi119ate5hxk.rtspplayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
import org.videolan.libvlc.util.VLCVideoLayout;
//import com.google.android.exoplayer2.ui.StyledPlayerView;



public class RTSP1Activity extends AppCompatActivity{

Player p;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rtsp1);
}

@Override
protected void onStart()
{
super.onStart();
Bundle extras = getIntent().getExtras();
String url = "";
if (extras == null) {
Expand All @@ -33,26 +25,20 @@ protected void onStart()
}
url = extras.getString("url");

if (url.isEmpty()) {
Log.d("NO URL","URL is empty");
super.onBackPressed();
return;
}
Log.d("URL",url);
LibVLC libVlc = new LibVLC(this);
MediaPlayer mediaPlayer = new MediaPlayer(libVlc);
VLCVideoLayout videoLayout = findViewById(R.id.videoLayout);

mediaPlayer.attachViews(videoLayout, null, false, false);
p = new Player(url,findViewById(R.id.videoLayout),this);
}

Media media = new Media(libVlc, Uri.parse(url));
media.setHWDecoderEnabled(true, false);
media.addOption(":network-caching=600");
@Override
protected void onStart()
{
super.onStart();

mediaPlayer.setMedia(media);
media.release();
mediaPlayer.play();
}

@Override
public void onStop() {
super.onStop();
p.stopPlayer();
}

}
Loading

0 comments on commit 11b11b0

Please sign in to comment.