Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

//GSYVideoPlayer
implementation 'com.shuyu:gsyVideoPlayer-java:8.1.2'
//是否需要ExoPlayer模式
implementation 'com.shuyu:GSYVideoPlayer-exo2:8.1.2'
//更多ijk的编码支持
implementation 'com.shuyu:gsyVideoPlayer-ex_so:8.1.2'

}
21 changes: 20 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile


-keep class com.shuyu.gsyvideoplayer.video.** { *; }
-dontwarn com.shuyu.gsyvideoplayer.video.**
-keep class com.shuyu.gsyvideoplayer.video.base.** { *; }
-dontwarn com.shuyu.gsyvideoplayer.video.base.**
-keep class com.shuyu.gsyvideoplayer.utils.** { *; }
-dontwarn com.shuyu.gsyvideoplayer.utils.**
-keep class tv.danmaku.ijk.** { *; }
-dontwarn tv.danmaku.ijk.**

-keep public class * extends android.view.View{
*** get*();
void set*(***);
public <init>(android.content.Context);
public <init>(android.content.Context, java.lang.Boolean);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
}
11 changes: 11 additions & 0 deletions app/src/main/java/it/danieleverducci/ojo/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import it.danieleverducci.ojo.entities.Camera;

Expand Down Expand Up @@ -49,6 +50,16 @@ public List<Camera> getCameras() {
return cameras;
}

public List<Camera> getEnabledCameras() {
List<Camera> result = new ArrayList<>();
for (int i = 0; i < cameras.size(); i++) {
if (cameras.get(i).getEnable() == 1) {
result.add(cameras.get(i));
}
}
return result;
}

public void setCameras(List<Camera> cameras) {
this.cameras = cameras;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,48 @@
import android.content.Context;
import android.content.SharedPreferences;

import it.danieleverducci.ojo.ui.videoplayer.VideoLibEnum;

public class SharedPreferencesManager {
private static final String SP_FILE = "sp_file_name";//sharedPreference's name

private static final String SP_ROTATION_ENABLED = "rot_en";
private static final String USE_WHICH_VIDEO_LIB = "USE_WHICH_VIDEO_LIB";

public static void saveRotationEnabled(Context ctx, boolean enabled) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_ROTATION_ENABLED, Context.MODE_PRIVATE);
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_FILE, Context.MODE_PRIVATE);
sharedPref.edit().putBoolean(SP_ROTATION_ENABLED, enabled).apply();
}

public static boolean loadRotationEnabled(Context ctx) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_ROTATION_ENABLED, Context.MODE_PRIVATE);
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_FILE, Context.MODE_PRIVATE);
return sharedPref.getBoolean(SP_ROTATION_ENABLED, false);
}

/**
* 1:exo
* 2:vlc
* 3:ijk
* 4:system
*
* @param ctx
* @param videoLibEnum
*/
public static void saveUseWhichLib(Context ctx, VideoLibEnum videoLibEnum) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_FILE, Context.MODE_PRIVATE);
sharedPref.edit().putInt(USE_WHICH_VIDEO_LIB, videoLibEnum.i).apply();
}

/**
* @param ctx
* @return
* 1:exo
* 2:vlc
* 3:ijk
* 4:system
*/
public static int useWhichLib(Context ctx) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_FILE, Context.MODE_PRIVATE);
return sharedPref.getInt(USE_WHICH_VIDEO_LIB, 1);
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/it/danieleverducci/ojo/entities/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Camera implements Serializable {
private static final long serialVersionUID = -3837361587400158910L;
private String name;
private String rtspUrl;
private int enable =1; //启用: 1 ; 关闭: 0

public Camera(String name, String rtspUrl) {
this.name = name;
Expand All @@ -27,4 +28,16 @@ public String getName() {
public String getRtspUrl() {
return rtspUrl;
}

public int getEnable() {
return enable;
}

/**
*
* @param enable 1:enable; 0:disable
*/
public void setEnable(int enable) {
this.enable = enable;
}
}
32 changes: 30 additions & 2 deletions app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import android.util.Log;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;

import com.shuyu.gsyvideoplayer.GSYVideoManager;

import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.SharedPreferencesManager;
Expand All @@ -35,7 +37,11 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(binding.getRoot());

// Show FAB only on first fragment
navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_content_main);
assert navHostFragment != null;
navController = navHostFragment.getNavController();

navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
if (destination.getId() == R.id.HomeFragment)
binding.fab.show();
Expand All @@ -59,7 +65,29 @@ public void setOnBackButtonPressedListener(OnBackButtonPressedListener onBackBut
public void onBackPressed() {
if (this.onBackButtonPressedListener != null && this.onBackButtonPressedListener.onBackPressed())
return;
if (GSYVideoManager.backFromWindowFull(this)) {
return;
}
super.onBackPressed();

}

@Override
protected void onPause() {
super.onPause();
GSYVideoManager.onPause();
}

@Override
protected void onResume() {
super.onResume();
GSYVideoManager.onResume();
}

@Override
protected void onDestroy() {
super.onDestroy();
GSYVideoManager.releaseAllVideos();
}

public void navigateToFragment(int actionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import java.util.List;

Expand All @@ -24,6 +25,7 @@
import it.danieleverducci.ojo.databinding.FragmentSettingsItemListBinding;
import it.danieleverducci.ojo.entities.Camera;
import it.danieleverducci.ojo.ui.adapters.SettingsRecyclerViewAdapter;
import it.danieleverducci.ojo.ui.videoplayer.VideoLibEnum;
import it.danieleverducci.ojo.utils.ItemMoveCallback;

/**
Expand All @@ -35,7 +37,7 @@ public class SettingsFragment extends Fragment {
private Settings settings;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = FragmentSettingsItemListBinding.inflate(inflater, container, false);

Expand Down Expand Up @@ -70,6 +72,33 @@ public boolean onMenuItemClick(MenuItem item) {
return false;
}
});

binding.radioGroup.clearCheck();
int whichlib = SharedPreferencesManager.useWhichLib(this.getActivity());
if (whichlib == 1) {
binding.exoR.setChecked(true);
} else if (whichlib == 2)
binding.vlcR.setChecked(true);
else if (whichlib == 3)
binding.ijkR.setChecked(true);
else if (whichlib ==4)
binding.sysR.setChecked(true);

binding.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.exo_r) {
SharedPreferencesManager.saveUseWhichLib(requireContext(), VideoLibEnum.EXO);
} else if (checkedId == R.id.vlc_r) {
SharedPreferencesManager.saveUseWhichLib(requireContext(), VideoLibEnum.VLC);
} else if (checkedId == R.id.ijk_r) {
SharedPreferencesManager.saveUseWhichLib(requireContext(), VideoLibEnum.IJK);
}else if (checkedId==R.id.sys_r){
SharedPreferencesManager.saveUseWhichLib(requireContext(), VideoLibEnum.SYSTEM);
}
}
});

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Load existing settings (if any)
settings = Settings.fromDisk(getContext());
settings = Settings.fromDisk(requireContext());
}

@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {

Expand All @@ -47,7 +47,7 @@ public View onCreateView(

Camera c = settings.getCameras().get(this.selectedCamera);
binding.streamName.setText(c.getName());
binding.streamName.setHint(getContext().getString(R.string.stream_list_default_camera_name).replace("{camNo}", (this.selectedCamera+1)+""));
binding.streamName.setHint(requireContext().getString(R.string.stream_list_default_camera_name).replace("{camNo}", (this.selectedCamera+1)+""));
binding.streamUrl.setText(c.getRtspUrl());
}

Expand Down
Loading