diff --git a/app/build.gradle b/app/build.gradle index a9cbc16..6b60b72 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } \ No newline at end of file diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/Player.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/Player.java new file mode 100644 index 0000000..79b8143 --- /dev/null +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/Player.java @@ -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"); + } + + +} diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP16Activity.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP16Activity.java index 50040d8..8709738 100644 --- a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP16Activity.java +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP16Activity.java @@ -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 pList =new ArrayList<>(); + ArrayList urlList = new ArrayList(); @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 urlList = new ArrayList(); if (extras == null) { Log.d("NO Extras","extras is null"); super.onBackPressed(); @@ -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 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(); + } } diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP1Activity.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP1Activity.java index 9a74999..8e0ce75 100644 --- a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP1Activity.java +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP1Activity.java @@ -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) { @@ -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(); + } } diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP4Activity.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP4Activity.java index d0c97a6..ccedb45 100644 --- a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP4Activity.java +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP4Activity.java @@ -1,36 +1,26 @@ package net.bi119ate5hxk.rtspplayer; -import android.net.Uri; import android.os.Bundle; import android.util.Log; - -import androidx.annotation.IdRes; 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 RTSP4Activity extends AppCompatActivity { - - - + ArrayList pList =new ArrayList<>(); + ArrayList urlList = new ArrayList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rtsp4); - } - @Override - protected void onStart() - { - super.onStart(); Bundle extras = getIntent().getExtras(); - ArrayList urlList = new ArrayList(); + if (extras == null) { Log.d("NO Extras","extras is null"); super.onBackPressed(); @@ -42,42 +32,31 @@ 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); + ArrayList 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)); + + for (int i = 0; i < urlList.size(); i++) { + pList.add(new Player(urlList.get(i), viewsList.get(i), this)); } + } + @Override + protected void onStart() + { + super.onStart(); } - protected void createVLCPlayer(String url, @IdRes int viewId){ - if (url.isEmpty()) { - Log.d("NO URL","URL is empty"); - return; + @Override + public void onStop() { + super.onStop(); + for (Player p : pList) { + p.stopPlayer(); } - Log.d("URL",url); - LibVLC libVlc = new LibVLC(this); - MediaPlayer mediaPlayer = new MediaPlayer(libVlc); - VLCVideoLayout videoLayout = findViewById(viewId); - - mediaPlayer.attachViews(videoLayout, null, false, false); - - Media media = new Media(libVlc, Uri.parse(url)); - media.setHWDecoderEnabled(true, false); - media.addOption(":network-caching=600"); - - mediaPlayer.setMedia(media); - media.release(); - mediaPlayer.play(); } + } diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP9Activity.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP9Activity.java index 0e83afb..e87df5e 100644 --- a/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP9Activity.java +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/RTSP9Activity.java @@ -1,32 +1,24 @@ package net.bi119ate5hxk.rtspplayer; -import android.net.Uri; import android.os.Bundle; import android.util.Log; - -import androidx.annotation.IdRes; import androidx.appcompat.app.AppCompatActivity; -import org.videolan.libvlc.LibVLC; -import org.videolan.libvlc.Media; -import org.videolan.libvlc.MediaPlayer; +import java.util.ArrayList; + +//import com.google.android.exoplayer2.ui.StyledPlayerView; import org.videolan.libvlc.util.VLCVideoLayout; -import java.util.ArrayList; public class RTSP9Activity extends AppCompatActivity { + ArrayList pList =new ArrayList<>(); + ArrayList urlList = new ArrayList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rtsp9); - } - @Override - protected void onStart() - { - super.onStart(); Bundle extras = getIntent().getExtras(); - ArrayList urlList = new ArrayList(); if (extras == null) { Log.d("NO Extras","extras is null"); super.onBackPressed(); @@ -38,56 +30,35 @@ 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); + ArrayList 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)); + + for (int i = 0; i < urlList.size(); i++) { + pList.add(new Player(urlList.get(i), viewsList.get(i),this)); } + } + @Override + protected void onStart() + { + super.onStart(); } - protected void createVLCPlayer(String url, @IdRes int viewId){ - if (url.isEmpty()) { - Log.d("NO URL","URL is empty"); - return; + @Override + public void onStop() { + super.onStop(); + for (Player p : pList) { + p.stopPlayer(); } - Log.d("URL",url); - LibVLC libVlc = new LibVLC(this); - MediaPlayer mediaPlayer = new MediaPlayer(libVlc); - VLCVideoLayout videoLayout = findViewById(viewId); - - mediaPlayer.attachViews(videoLayout, null, false, false); - - Media media = new Media(libVlc, Uri.parse(url)); - media.setHWDecoderEnabled(true, false); - media.addOption(":network-caching=600"); - - mediaPlayer.setMedia(media); - media.release(); - mediaPlayer.play(); } - } + diff --git a/app/src/main/java/net/bi119ate5hxk/rtspplayer/SettingsActivity.java b/app/src/main/java/net/bi119ate5hxk/rtspplayer/SettingsActivity.java index 271bc7d..2f06ea6 100644 --- a/app/src/main/java/net/bi119ate5hxk/rtspplayer/SettingsActivity.java +++ b/app/src/main/java/net/bi119ate5hxk/rtspplayer/SettingsActivity.java @@ -20,6 +20,7 @@ public class SettingsActivity extends AppCompatActivity{ private static SharedPreferences sharedPref; + private static ArrayList tfViewsList =new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -29,22 +30,23 @@ protected void onCreate(Bundle savedInstanceState) { sharedPref = getSharedPreferences("appPref", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); - TextView urlTextF1 = findViewById(R.id.urlField1); - TextView urlTextF2 = findViewById(R.id.urlField2); - TextView urlTextF3 = findViewById(R.id.urlField3); - TextView urlTextF4 = findViewById(R.id.urlField4); - TextView urlTextF5 = findViewById(R.id.urlField5); - TextView urlTextF6 = findViewById(R.id.urlField6); - TextView urlTextF7 = findViewById(R.id.urlField7); - TextView urlTextF8 = findViewById(R.id.urlField8); - TextView urlTextF9 = findViewById(R.id.urlField9); - TextView urlTextF10 = findViewById(R.id.urlField10); - TextView urlTextF11 = findViewById(R.id.urlField11); - TextView urlTextF12 = findViewById(R.id.urlField12); - TextView urlTextF13 = findViewById(R.id.urlField13); - TextView urlTextF14 = findViewById(R.id.urlField14); - TextView urlTextF15 = findViewById(R.id.urlField15); - TextView urlTextF16 = findViewById(R.id.urlField16); + tfViewsList.add(findViewById(R.id.urlField1)); + tfViewsList.add(findViewById(R.id.urlField2)); + tfViewsList.add(findViewById(R.id.urlField3)); + tfViewsList.add(findViewById(R.id.urlField4)); + tfViewsList.add(findViewById(R.id.urlField5)); + tfViewsList.add(findViewById(R.id.urlField6)); + tfViewsList.add(findViewById(R.id.urlField7)); + tfViewsList.add(findViewById(R.id.urlField8)); + tfViewsList.add(findViewById(R.id.urlField9)); + tfViewsList.add(findViewById(R.id.urlField10)); + tfViewsList.add(findViewById(R.id.urlField11)); + tfViewsList.add(findViewById(R.id.urlField12)); + tfViewsList.add(findViewById(R.id.urlField13)); + tfViewsList.add(findViewById(R.id.urlField14)); + tfViewsList.add(findViewById(R.id.urlField15)); + tfViewsList.add(findViewById(R.id.urlField16)); + Set urlArrSetR = sharedPref.getStringSet("urlArrSet",new HashSet()); List list = new ArrayList(urlArrSetR); @@ -55,23 +57,10 @@ protected void onCreate(Bundle savedInstanceState) { urlStrArr[i] = str; i++; } + for (int j = 0; j < urlStrArr.length; j++) { + tfViewsList.get(j).setText(urlStrArr[j]); + } - urlTextF1.setText(urlStrArr[0]); - urlTextF2.setText(urlStrArr[1]); - urlTextF3.setText(urlStrArr[2]); - urlTextF4.setText(urlStrArr[3]); - urlTextF5.setText(urlStrArr[4]); - urlTextF6.setText(urlStrArr[5]); - urlTextF7.setText(urlStrArr[6]); - urlTextF8.setText(urlStrArr[7]); - urlTextF9.setText(urlStrArr[8]); - urlTextF10.setText(urlStrArr[9]); - urlTextF11.setText(urlStrArr[10]); - urlTextF12.setText(urlStrArr[11]); - urlTextF13.setText(urlStrArr[12]); - urlTextF14.setText(urlStrArr[13]); - urlTextF15.setText(urlStrArr[14]); - urlTextF16.setText(urlStrArr[15]); Button button = (Button) findViewById(R.id.doneBTN); @@ -81,22 +70,10 @@ public void onClick(View v) { TreeSet urlArrSet = new TreeSet(); - urlArrSet.add(urlTextF1.getText().toString().trim()); - urlArrSet.add(urlTextF2.getText().toString().trim()); - urlArrSet.add(urlTextF3.getText().toString().trim()); - urlArrSet.add(urlTextF4.getText().toString().trim()); - urlArrSet.add(urlTextF5.getText().toString().trim()); - urlArrSet.add(urlTextF6.getText().toString().trim()); - urlArrSet.add(urlTextF7.getText().toString().trim()); - urlArrSet.add(urlTextF8.getText().toString().trim()); - urlArrSet.add(urlTextF9.getText().toString().trim()); - urlArrSet.add(urlTextF10.getText().toString().trim()); - urlArrSet.add(urlTextF11.getText().toString().trim()); - urlArrSet.add(urlTextF12.getText().toString().trim()); - urlArrSet.add(urlTextF13.getText().toString().trim()); - urlArrSet.add(urlTextF14.getText().toString().trim()); - urlArrSet.add(urlTextF15.getText().toString().trim()); - urlArrSet.add(urlTextF16.getText().toString().trim()); + for (int j = 0; j < urlStrArr.length; j++) { + urlArrSet.add(tfViewsList.get(j).getText().toString().trim()); + } + if (urlArrSet.contains("")){ urlArrSet.remove(""); } diff --git a/app/src/main/res/layout/activity_rtsp1.xml b/app/src/main/res/layout/activity_rtsp1.xml index fb73b08..9791e99 100644 --- a/app/src/main/res/layout/activity_rtsp1.xml +++ b/app/src/main/res/layout/activity_rtsp1.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".RTSP1Activity" android:keepScreenOn="true">