PageRenderTime 195ms CodeModel.GetById 2ms RepoModel.GetById 1ms app.codeStats 0ms

/app/src/main/java/de/kraftcom/asemobile/RtspPlayerActivity.java

https://bitbucket.org/cheban_natali/rtspplayer
Java | 1590 lines | 1204 code | 240 blank | 146 comment | 205 complexity | 7eb22cae664b7663e6148b121f7e78db MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. package de.kraftcom.asemobile;
  2. import android.annotation.TargetApi;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.content.res.Configuration;
  8. import android.content.res.Resources;
  9. import android.database.sqlite.SQLiteDatabase;
  10. import android.graphics.PixelFormat;
  11. import android.media.MediaRouter;
  12. import android.net.Uri;
  13. import android.os.AsyncTask;
  14. import android.os.Build;
  15. import android.os.Bundle;
  16. import android.os.Handler;
  17. import android.os.SystemClock;
  18. import android.support.v7.app.AlertDialog;
  19. import android.support.v7.app.AppCompatActivity;
  20. import android.support.v7.widget.LinearLayoutManager;
  21. import android.support.v7.widget.PopupMenu;
  22. import android.support.v7.widget.RecyclerView;
  23. import android.util.Log;
  24. import android.view.Gravity;
  25. import android.view.LayoutInflater;
  26. import android.view.Menu;
  27. import android.view.MotionEvent;
  28. import android.view.SurfaceHolder;
  29. import android.view.SurfaceView;
  30. import android.view.TextureView;
  31. import android.view.View;
  32. import android.view.ViewGroup;
  33. import android.view.ViewStub;
  34. import android.widget.ArrayAdapter;
  35. import android.widget.Button;
  36. import android.widget.FrameLayout;
  37. import android.widget.ImageButton;
  38. import android.widget.LinearLayout;
  39. import android.widget.ListView;
  40. import android.widget.RelativeLayout;
  41. import android.widget.TextView;
  42. import android.widget.Toast;
  43. //import de.kraftcom.R;
  44. import de.kraftcom.asemobile.adapter.ChannelRecyclerAdapter;
  45. import de.kraftcom.asemobile.adapter.MediaInfoAdapter;
  46. import de.kraftcom.asemobile.model.ChannelList;
  47. import de.kraftcom.asemobile.model.ChannelStateInfo;
  48. import de.kraftcom.asemobile.model.DataBaseHandel;
  49. import de.kraftcom.asemobile.model.MyApp;
  50. import de.kraftcom.asemobile.model.RecyclerItemClickListener;
  51. import de.kraftcom.asemobile.model.modelEpg.ChannelEpg;
  52. import de.kraftcom.asemobile.model.modelEpg.Programme;
  53. import de.kraftcom.asemobile.util.PreferencesUtils;
  54. import org.json.JSONArray;
  55. import org.json.JSONException;
  56. import org.json.JSONObject;
  57. import org.videolan.libvlc.AWindow;
  58. import org.videolan.libvlc.IVLCVout;
  59. import org.videolan.libvlc.LibVLC;
  60. import org.videolan.libvlc.Media;
  61. import org.videolan.libvlc.MediaPlayer;
  62. import org.videolan.libvlc.util.VLCUtil;
  63. import java.io.ByteArrayInputStream;
  64. import java.io.ByteArrayOutputStream;
  65. import java.io.Closeable;
  66. import java.io.IOException;
  67. import java.io.InterruptedIOException;
  68. import java.io.ObjectInputStream;
  69. import java.io.ObjectOutputStream;
  70. import java.lang.ref.WeakReference;
  71. import java.text.SimpleDateFormat;
  72. import java.util.ArrayList;
  73. import java.util.Calendar;
  74. import java.util.HashMap;
  75. import java.util.LinkedList;
  76. import java.util.List;
  77. import static de.kraftcom.asemobile.util.PreferencesUtils.CHANNEL_INFO;
  78. import static de.kraftcom.asemobile.util.PreferencesUtils.CHECK_BTN_SUB;
  79. public class RtspPlayerActivity extends AppCompatActivity implements IVLCVout.Callback, View.OnClickListener, View.OnTouchListener/*, MediaPlayer.EventListener,Media.EventListener */ {
  80. @SuppressWarnings("unused")
  81. public static final int HW_ACCELERATION_AUTOMATIC = -1;
  82. public static final int HW_ACCELERATION_DISABLED = 0;
  83. public static final int HW_ACCELERATION_DECODING = 1;
  84. public static final int HW_ACCELERATION_FULL = 2;
  85. public static final int AFTER_WEB = 1;
  86. public static final int AFTER_CHANGE_CANNEL = 2;
  87. public static final int AFTER_REPING = 3;
  88. public static final int AFTER_LOST_SERVER = 4;
  89. private static final boolean USE_SURFACE_VIEW = true;
  90. //private static boolean ENABLE_SUBTITLES = false;
  91. private static boolean ENABLE_SUBTITLES;
  92. public final static String TAG = "RtspPlayerActivity";
  93. public final String LOG_TAG = "Player";
  94. private static final int SURFACE_BEST_FIT = 0;
  95. private static final int SURFACE_FIT_SCREEN = 1;
  96. private static final int SURFACE_FILL = 2;
  97. private static final int SURFACE_16_9 = 3;
  98. private static final int SURFACE_4_3 = 4;
  99. private static final int SURFACE_ORIGINAL = 5;
  100. private static int CURRENT_SIZE = SURFACE_BEST_FIT;
  101. private FrameLayout mVideoSurfaceFrame = null;
  102. private SurfaceView mVideoSurface = null;
  103. private SurfaceView mSubtitlesSurfaceView = null;
  104. private SurfaceHolder mSubtitlesSurfaceHolder;
  105. private View mChannelView = null, channelSurfaceStub;
  106. private TextureView mVideoTexture = null;
  107. private View mVideoView = null;
  108. private RelativeLayout videoState;
  109. private AWindow mAWindow = null;
  110. private ParseTracksTask mParseTracksTask = null;
  111. private MediaRouter mMediaRouter;
  112. private MediaRouter.SimpleCallback mMediaRouterCallback;
  113. private MediaInfoAdapter mAdapter;
  114. private MediaPlayer.EventListener mPlayerListener = new MyPlayerListener(this);
  115. private ViewStub textureStub, subtitlesSurfaceStub, stub;
  116. private final Handler mHandler = new Handler();
  117. private View.OnLayoutChangeListener mOnLayoutChangeListener = null;
  118. private int mCurrentAudioTrack = -2, mCurrentSpuTrack = -2;
  119. public String mFilePatch, mNameChannel,loc, mlangChannel,mChannelType;
  120. private SurfaceView mSurface;
  121. private SurfaceHolder holder;
  122. private LibVLC mLibVLC = null;
  123. private MediaPlayer mMediaPlayer = null;
  124. private int mVideoWidth = 0;
  125. private int mVideoHeight = 0;
  126. private int mVideoVisibleHeight = 0;
  127. private int mVideoVisibleWidth = 0;
  128. private int mVideoSarNum = 0;
  129. private int mVideoSarDen = 0;
  130. public IVLCVout vlcVout;
  131. Media media;
  132. // Serializable channels;
  133. ArrayList<ChannelList> channels;
  134. //TextView ;
  135. Button btExitTV, btSubTitre;
  136. RecyclerView channelRecycler;//, infoSubRecycler;
  137. LinearLayout channelPlace, placeSub, errorPlace, llSub;
  138. TextView textError, tvChannelName;
  139. boolean is_bt_menu = false, is_menu=true;
  140. //ListView lvProgram;
  141. // ArrayList<String> programma;
  142. //public DataBaseHandel dataBaseHandel;
  143. SQLiteDatabase db;
  144. String currentDate;
  145. Calendar currentTime;
  146. Context context;
  147. String mArray;
  148. public static TextView mTextSub;
  149. // List<ChannelEpg> channelList = new ArrayList<ChannelEpg>();
  150. /// List<Programme> programmelList = new ArrayList<Programme>();
  151. List<ChannelStateInfo> channelStateInfoList;
  152. private boolean mHasSubItems = false;
  153. private MediaPlayer.TrackDescription[] mAudioTracksList;
  154. private MediaPlayer.TrackDescription[] mSubtitleTracksList;
  155. private final ArrayList<String> mSubtitleSelectedFiles = new ArrayList<>();
  156. private boolean mPlaybackStarted = false;
  157. private AlertDialog mAlertDialog;
  158. public int currentTrack, listPosition;
  159. public String[] nameList;
  160. public int[] idList;
  161. public int ScreenWidth, ScreenHeight, btSubTitreWidth, btSubTitreHeight;
  162. private long mForcedTime = -1;
  163. private long mLastTime = -1;
  164. private int mLastAudioTrack = -2;
  165. private int mLastSpuTrack = -2;
  166. private SharedPreferences mSettings;
  167. private Uri mUri;
  168. public HashMap<String, String> channelStateInfo = new HashMap<String, String>();
  169. private SubtitlesGetTask mSubtitlesGetTask = null;
  170. SharedPreferences prefs;
  171. public int countNotChannel=0;
  172. public Boolean startAfterWeb=false,//1
  173. startAfterChangeCannel=false,//2
  174. startAfterReping=false,//3
  175. startAfterLostServer=false,
  176. isSaveChannel=false,
  177. btnIsSingle = false,
  178. btnIsAll = false,
  179. btnNoActive = false,
  180. activationChannel = false;//4
  181. public int track_audio, subtitles, track_video, exit_tv, invalid_location, invalid_subtitles,
  182. track_text, idTrackOn, idtrackOff, error_text;
  183. public int checkBtnSub;
  184. public long timer=5000;
  185. public long timerT=2200;
  186. Handler handler = new Handler();
  187. final Runnable r = new Runnable() {
  188. public void run() {
  189. handler.postDelayed(this, timer);
  190. statusCheck();
  191. }
  192. };
  193. final Runnable t = new Runnable() {
  194. public void run() {
  195. handler.postDelayed(this, timerT);
  196. RecyclerItemClic();
  197. }
  198. };
  199. @Override
  200. protected void onCreate(Bundle savedInstanceState) {
  201. super.onCreate(savedInstanceState);
  202. setContentView(R.layout.activity_rtsp_player_new);
  203. ScreenWidth = getScreenWidth();
  204. ScreenHeight = getScreenHeight();
  205. prefs = getSharedPreferences(PreferencesUtils.PREFERENCES_FILE, 0);
  206. Bundle extras = getIntent().getExtras();
  207. if (extras != null) {
  208. mArray = extras.getString("Array");
  209. mFilePatch = extras.getString("TEXT_URL");
  210. mNameChannel = extras.getString("TEXT_NAME");
  211. mlangChannel = extras.getString("TEXT_LANG");
  212. mChannelType = extras.getString("TEXT_TYPE");
  213. is_menu = Boolean.parseBoolean(extras.getString("IS_MENU"));
  214. isSaveChannel=false;
  215. Log.d(LOG_TAG, "TEXT_LANG mlangChannel = "+ mlangChannel);
  216. }else{
  217. mFilePatch = PreferencesUtils.readStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO_FILE,null);
  218. }
  219. //mFilePatch = "rtsp://192.168.254.193:554/?src=1&freq=11494&pol=h&ro=0.35&msys=dvbs2&mtype=8psk&plts=on&sr=22000&fec=23&pids=0,17,18,5100,5101,5102,5104";
  220. // mFilePatch = "http://sochi-strk.ru:1936/strk/strk.stream/playlist.m3u8";
  221. // channels.add("0","Россия 24 ","http://46.174.255.8:8000/udp/239.192.3.71:1234/","ru","video");
  222. // String id,String channelTitle, String channelUrl, String channelLang, String channelType
  223. loc=PreferencesUtils.readStrSharedSetting(getApplicationContext(), PreferencesUtils.LOCALE,null);
  224. ENABLE_SUBTITLES = PreferencesUtils.readBoolSharedSetting(getApplicationContext(), PreferencesUtils.CHECK_BTN_SUB, false);
  225. checkBtnSub = ENABLE_SUBTITLES ? 1: 0;
  226. setLanguege(loc);
  227. initUI();
  228. getCurrentData();
  229. getWindow().getDecorView().setSystemUiVisibility(
  230. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  231. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  232. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  233. | View.SYSTEM_UI_FLAG_FULLSCREEN
  234. | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  235. );
  236. // dataBaseHandel = new DataBaseHandel(this);
  237. // db = dataBaseHandel.getReadableDatabase();
  238. //saveChannelState(mFilePatch,mCurrentSpuTrack);
  239. mUri=Uri.parse(mFilePatch);
  240. channels = getChannelsWeb(mArray);
  241. /* channelList = dataBaseHandel.getAllChannel();
  242. programmelList = dataBaseHandel.getAllProgramme();
  243. db.close();*/
  244. context = getApplicationContext();
  245. initPlayer();
  246. btExitTV.setOnClickListener(this);
  247. btSubTitre.setOnClickListener(this);
  248. mMediaPlayer.setEventListener(mPlayerListener);
  249. channelRecycler.addOnItemTouchListener(new RecyclerItemClickListener(getApplicationContext(), new RecyclerItemClickListener.OnItemClickListener() {
  250. @Override
  251. public void onItemClick(View view, int position) {
  252. errorPlace.setVisibility(View.INVISIBLE);
  253. tvChannelName.setText("");
  254. mFilePatch = channels.get(position).getChannelUrl();
  255. mChannelType= channels.get(position).getType();
  256. mNameChannel=channels.get(position).getTitle();
  257. mUri=Uri.parse(mFilePatch);
  258. if(vlcVout.areViewsAttached()){
  259. if(mVideoSurface.getVisibility()==View.VISIBLE){mVideoSurface.setVisibility(View.INVISIBLE);}
  260. vlcVout.detachViews();
  261. }
  262. if(!mChannelType.equals("radio")) {
  263. btSubTitre.setVisibility(View.VISIBLE);
  264. if(mVideoSurface.getVisibility()==View.INVISIBLE){mVideoSurface.setVisibility(View.VISIBLE);}
  265. mVideoView = mVideoSurface;
  266. vlcVout.setVideoView(mVideoSurface);
  267. vlcVout.attachViews();
  268. if (mSubtitlesSurfaceView != null)
  269. vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
  270. }else{
  271. tvChannelName.setText(mNameChannel);
  272. btSubTitre.setVisibility(View.INVISIBLE);
  273. mVideoView = mVideoTexture;
  274. vlcVout.setVideoView(mVideoTexture);
  275. }
  276. if (r != null) {
  277. handler.removeCallbacks(r);
  278. }
  279. handler.postDelayed(r, timer);
  280. media = new Media(mLibVLC, mUri);
  281. mMediaPlayer.setMedia(media);
  282. media.parse();
  283. media.release();
  284. mMediaPlayer.play();
  285. activationChannel = false;
  286. isSaveChannel=false;
  287. getSubtitles();
  288. // RecyclerItemClic();
  289. // Log.d(LOG_TAG, "channelRecycler : " + "mCurrentSpuTrack= " + Integer.toString(mCurrentSpuTrack) + " mFilePatch=" + mFilePatch);
  290. /* mNameChannel = channels.get(position).getChannelTitle();
  291. getProgram(mNameChannel);
  292. ArrayAdapter<String> progAdapter = new ArrayAdapter(getApplicationContext(), R.layout.item_program_list, programma);
  293. programPlace.setVisibility(View.VISIBLE);
  294. lvProgram.setVisibility(View.VISIBLE);
  295. lvProgram.setAdapter(progAdapter);*/
  296. flagsStart(AFTER_CHANGE_CANNEL);
  297. handler.postDelayed(t, timerT);
  298. }
  299. }));
  300. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO_SUBTITLE_FILES, null);
  301. handler.postDelayed(r, timer);
  302. if(mChannelType.equals("radio")) {
  303. showMenu(true);
  304. tvChannelName.setText(mNameChannel);
  305. } else{
  306. showMenu(is_menu);
  307. tvChannelName.setText("");
  308. }
  309. }
  310. public void saveChannelInPrefs(String channelUri){
  311. isSaveChannel=true;
  312. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO_FILE, channelUri);
  313. }
  314. public void RecyclerItemClic(){
  315. setScanTrack();
  316. }
  317. public void setLanguege(String lang) {
  318. if ((lang == null) || lang.equals("EN")) {
  319. track_audio = R.string.track_audio;
  320. subtitles = R.string.subtitles;
  321. exit_tv = R.string.exit_tv;
  322. error_text = R.string.error_channel;
  323. invalid_location = R.string.invalid_location;
  324. invalid_subtitles = R.string.invalid_subtitles;
  325. MediaInfoAdapter.track_video = R.string.track_video;
  326. MediaInfoAdapter.track_audio = R.string.track_audio;
  327. MediaInfoAdapter.track_text = R.string.track_text;
  328. track_text = R.string.track_text;
  329. MediaInfoAdapter.track_unknown = R.string.track_unknown;
  330. MediaInfoAdapter.track_bitrate_info = R.string.track_bitrate_info;
  331. MediaInfoAdapter.track_codec_info = R.string.track_codec_info;
  332. MediaInfoAdapter.track_channels_info_quantity = R.plurals.track_channels_info_quantity;
  333. MediaInfoAdapter.track_language_info = R.string.track_language_info;
  334. MediaInfoAdapter.track_samplerate_info = R.string.track_samplerate_info;
  335. MediaInfoAdapter.track_resolution_info = R.string.track_resolution_info;
  336. MediaInfoAdapter.track_framerate_info = R.string.track_framerate_info;
  337. } else {
  338. track_audio = R.string.track_audio;
  339. subtitles = R.string.subtitles;
  340. exit_tv = R.string.exit_tv;
  341. error_text = R.string.error_channel;
  342. invalid_location = R.string.invalid_location;
  343. invalid_subtitles = R.string.invalid_subtitles;
  344. MediaInfoAdapter.track_video = R.string.track_video;
  345. MediaInfoAdapter.track_audio = R.string.track_audio;
  346. MediaInfoAdapter.track_text = R.string.track_text;
  347. track_text = R.string.track_text;
  348. MediaInfoAdapter.track_unknown = R.string.track_unknown;
  349. MediaInfoAdapter.track_bitrate_info = R.string.track_bitrate_info;
  350. MediaInfoAdapter.track_codec_info = R.string.track_codec_info;
  351. MediaInfoAdapter.track_channels_info_quantity = R.plurals.track_channels_info_quantity;
  352. MediaInfoAdapter.track_language_info = R.string.track_language_info;
  353. MediaInfoAdapter.track_samplerate_info = R.string.track_samplerate_info;
  354. MediaInfoAdapter.track_resolution_info = R.string.track_resolution_info;
  355. MediaInfoAdapter.track_framerate_info = R.string.track_framerate_info;
  356. /* track_audio = R.string.track_audio_de;
  357. subtitles = R.string.subtitles_de;
  358. exit_tv = R.string.exit_tv_de;
  359. invalid_location = R.string.invalid_location_de;
  360. invalid_subtitles = R.string.invalid_subtitles_de;
  361. MediaInfoAdapter.track_video = R.string.track_video_de;
  362. MediaInfoAdapter.track_audio = R.string.track_audio_de;
  363. MediaInfoAdapter.track_text = R.string.track_text_de;
  364. track_text = R.string.track_text_de;
  365. MediaInfoAdapter.track_unknown = R.string.track_unknown_de;
  366. MediaInfoAdapter.track_bitrate_info = R.string.track_bitrate_info_de;
  367. MediaInfoAdapter.track_codec_info = R.string.track_codec_info_de;
  368. MediaInfoAdapter.track_channels_info_quantity = R.plurals.track_channels_info_quantity_de;
  369. MediaInfoAdapter.track_language_info = R.string.track_language_info_de;
  370. MediaInfoAdapter.track_samplerate_info = R.string.track_samplerate_info_de;
  371. MediaInfoAdapter.track_resolution_info = R.string.track_resolution_info_de;
  372. MediaInfoAdapter.track_framerate_info = R.string.track_framerate_info_de;*/
  373. }
  374. }
  375. public void statusCheck(){
  376. if(!mChannelType.equals("radio")){
  377. if((mMediaPlayer!=null)&&(mUri!=null)&& (mMediaPlayer.isPlaying())&&(activationChannel==true)&& (mMediaPlayer.getVideoTracksCount()!=0) ) {
  378. countNotChannel=0;
  379. if (isSaveChannel == false) {
  380. saveChannelInPrefs(mFilePatch);
  381. }
  382. }else{
  383. if((activationChannel==true)&&(mMediaPlayer.getVideoTracksCount()!=0)){
  384. if(r!=null){
  385. handler.removeCallbacks(r);
  386. }
  387. countNotChannel=0;
  388. finish();
  389. startActivity(getIntent());
  390. }else {
  391. if(mMediaPlayer.getVideoTracksCount()==0){
  392. countNotChannel++;
  393. if (countNotChannel == 3) {
  394. mMediaPlayer.stop();
  395. if(r!=null){
  396. handler.removeCallbacks(r);
  397. }
  398. errorPlace.setVisibility(View.VISIBLE);
  399. /*Intent intenterr = new Intent(RtspPlayerActivity.this, ErrorActivity.class);
  400. intenterr.putExtra("mFilePatch", mFilePatch);
  401. intenterr.putExtra("Array", mArray);
  402. intenterr.putExtra("TEXT_NAME", mNameChannel);
  403. intenterr.putExtra("TEXT_LANG", mlangChannel);
  404. intenterr.putExtra("TEXT_TYPE", mChannelType);
  405. finish();
  406. startActivity(intenterr);*/
  407. // Toast.makeText(this, getResources().getText(invalid_location), Toast.LENGTH_LONG).show();
  408. }
  409. }
  410. }
  411. }
  412. }else
  413. if(mChannelType.equals("radio")){
  414. if((mMediaPlayer!=null)&&(mUri!=null)&& (mMediaPlayer.getAudioTracksCount()==0) ) {
  415. if(r!=null){
  416. handler.removeCallbacks(r);
  417. }
  418. errorPlace.setVisibility(View.VISIBLE);
  419. }
  420. }/*else
  421. handler.removeCallbacks(r);*/
  422. }
  423. public static ArrayList<ChannelList> getChannelsWeb(String ar) {
  424. ArrayList<ChannelList> mList = new ArrayList<ChannelList>();
  425. JSONArray myjson = null;
  426. try {
  427. myjson = new JSONArray(ar);
  428. } catch (JSONException e) {
  429. e.printStackTrace();
  430. }
  431. for (int i = 0; i < myjson.length(); i++) {
  432. try {
  433. JSONObject c = myjson.getJSONObject(i);
  434. String t = c.getString("title");
  435. String u = c.getString("url");
  436. String l = c.getString("lang");
  437. String tp = c.getString("type");
  438. String m = c.getString("ismenu");
  439. mList.add(new ChannelList(String.valueOf(i), t, u,l,tp,m));
  440. } catch (JSONException e) {
  441. e.printStackTrace();
  442. }
  443. }
  444. return mList;
  445. }
  446. public void flagsStart(int after) {
  447. switch (after) {
  448. case AFTER_WEB:
  449. startAfterWeb=true;
  450. startAfterChangeCannel=false;
  451. startAfterReping=false;
  452. startAfterLostServer=false;
  453. Log.d(LOG_TAG,"onStart AFTER_WEB");
  454. break;
  455. case AFTER_CHANGE_CANNEL:
  456. startAfterWeb=false;
  457. startAfterChangeCannel=true;
  458. startAfterReping=false;
  459. startAfterLostServer=false;
  460. Log.d(LOG_TAG,"onStart AFTER_CHANGE_CANNEL");
  461. break;
  462. case AFTER_REPING:
  463. startAfterWeb=false;
  464. startAfterChangeCannel=false;
  465. startAfterReping=true;
  466. startAfterLostServer=false;
  467. Log.d(LOG_TAG,"onStart AFTER_REPING");
  468. break;
  469. case AFTER_LOST_SERVER:
  470. startAfterWeb=false;
  471. startAfterChangeCannel=false;
  472. startAfterReping=false;
  473. startAfterLostServer=true;
  474. Log.d(LOG_TAG,"onStart AFTER_LOST_SERVER");
  475. break;
  476. }
  477. }
  478. /* public void getProgram(String st) {
  479. programma = new ArrayList<String>();
  480. String searchId = "", stN = "", curD = "", sercId = "";
  481. for (int j = 0; j < channelList.size(); j++) {
  482. stN = channelList.get(j).getChannelNameText();
  483. if (stN.equals(st)) {
  484. searchId = channelList.get(j).getChannelId();
  485. break;
  486. }
  487. }
  488. String curentDate = getCurrentData();
  489. for (int i = 0; i < programmelList.size(); i++) {
  490. curD = programmelList.get(i).getDateStart();
  491. sercId = programmelList.get(i).getChannelId();
  492. if ((curD.equals(currentDate) && (sercId.equals(searchId)))) {
  493. String timeStart = programmelList.get(i).getTimeStart();
  494. String timeStop = programmelList.get(i).getTimeStop();
  495. programma.add(" " + timeStart + "-" + timeStop + " " + programmelList.get(i).getProgTitleText());
  496. }
  497. }
  498. }*/
  499. public void initUI() {
  500. stub = findViewById(R.id.surface_stub);
  501. mVideoSurface = (SurfaceView) stub.inflate();
  502. textureStub = findViewById(R.id.texture_stub);
  503. mVideoTexture = (TextureView) textureStub.inflate();
  504. tvChannelName = findViewById(R.id.tvChannelName);
  505. channelPlace = findViewById(R.id.llChannels);
  506. errorPlace = findViewById(R.id.ll_text_error);
  507. channelRecycler = findViewById(R.id.rvChannels);
  508. btSubTitre = findViewById(R.id.btSubTitre);
  509. btSubTitre.setText(subtitles);
  510. textError = findViewById(R.id.text_error);
  511. textError.setText(error_text);
  512. btExitTV = findViewById(R.id.btExitTV);
  513. btExitTV.setText(exit_tv);
  514. placeSub = findViewById(R.id.ll_sub);
  515. llSub = findViewById(R.id.ll_text_sub);
  516. mVideoSurfaceFrame = findViewById(R.id.video_surface_frame);
  517. videoState = findViewById(R.id.video_state);
  518. tvChannelName.setText("");
  519. }
  520. public static int getScreenWidth() {
  521. // return Resources.getSystem().getDisplayMetrics().widthPixels;
  522. return Resources.getSystem().getDisplayMetrics().widthPixels;
  523. }
  524. public static int getScreenHeight() {
  525. return Resources.getSystem().getDisplayMetrics().heightPixels;
  526. }
  527. public String getCurrentData() {
  528. currentTime = Calendar.getInstance();
  529. SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
  530. currentDate = df.format(currentTime.getTime());
  531. return currentDate;
  532. }
  533. public void initPlayer() {
  534. final ArrayList<String> options = new ArrayList<>();
  535. mLibVLC = new LibVLC(context, options);//3.0.4 lib
  536. mMediaPlayer = new MediaPlayer(mLibVLC);
  537. if (!mChannelType.equals("radio")) {
  538. mVideoView = mVideoSurface;
  539. // btSubTitre.setVisibility(View.VISIBLE);
  540. } else {
  541. // btSubTitre.setVisibility(View.INVISIBLE);
  542. mVideoView = mVideoTexture;
  543. }
  544. mVideoView.setOnTouchListener(this);
  545. }
  546. private static String getResampler() {
  547. final VLCUtil.MachineSpecs m = VLCUtil.getMachineSpecs();
  548. return (m == null || m.processors > 2) ? "soxr" : "ugly";
  549. }
  550. private static int getDeblocking(int deblocking) {
  551. int ret = deblocking;
  552. if (deblocking < 0) {
  553. VLCUtil.MachineSpecs m = VLCUtil.getMachineSpecs();
  554. if (m == null)
  555. return ret;
  556. if ((m.hasArmV6 && !(m.hasArmV7)) || m.hasMips)
  557. ret = 4;
  558. else if (m.frequency >= 1200 && m.processors > 2)
  559. ret = 1;
  560. else if (m.bogoMIPS >= 1200 && m.processors > 2) {
  561. ret = 1;
  562. //Log.d(TAG, "Used bogoMIPS due to lack of frequency info");
  563. } else
  564. ret = 3;
  565. } else if (deblocking > 4) { // sanity check
  566. ret = 3;
  567. }
  568. return ret;
  569. }
  570. @Override
  571. protected void onStart() {
  572. super.onStart();
  573. Log.d(LOG_TAG,"onStart");
  574. // is_menu=false;
  575. activationChannel=false;
  576. vlcVout = mMediaPlayer.getVLCVout();
  577. vlcVout.addCallback(this);
  578. mMediaPlayer.setEventListener(mPlayerListener);
  579. if ((mVideoSurface != null)&&!mChannelType.equals("radio")) {
  580. btSubTitre.setVisibility(View.VISIBLE);
  581. vlcVout.setVideoView(mVideoSurface);
  582. vlcVout.attachViews();
  583. if (mSubtitlesSurfaceView != null)
  584. vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
  585. } else {
  586. btSubTitre.setVisibility(View.INVISIBLE);
  587. vlcVout.setVideoView(mVideoTexture);
  588. }
  589. Media media = new Media(mLibVLC, mUri);
  590. mMediaPlayer.setMedia(media);
  591. media.parse();
  592. Log.d("LOG_TAG","!!!!! media.getMeta = "+ media.getMeta(getTaskId()));
  593. ////////////////////////////////////////////////////////////////////////
  594. getSubtitles();
  595. media.release();
  596. mLastAudioTrack = mMediaPlayer.getAudioTrack();
  597. mLastSpuTrack = mMediaPlayer.getSpuTrack();
  598. mMediaPlayer.play();
  599. mMediaPlayer.getVideoTrack();
  600. flagsStart(AFTER_WEB);
  601. //Log.d(LOG_TAG, "onStart: " + "mCurrentSpuTrack=" + Integer.toString(mCurrentSpuTrack) + " mLastSpuTrack=" + Integer.toString(mLastSpuTrack) + " ENABLE_SUBTITLES=" + Boolean.toString(ENABLE_SUBTITLES));
  602. if (mOnLayoutChangeListener == null) {
  603. mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
  604. private final Runnable mRunnable = new Runnable() {
  605. @Override
  606. public void run() {
  607. updateVideoSurfaces();
  608. }
  609. };
  610. @Override
  611. public void onLayoutChange(View v, int left, int top, int right,
  612. int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
  613. if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
  614. mHandler.removeCallbacks(mRunnable);
  615. mHandler.post(mRunnable);
  616. }
  617. }
  618. };
  619. }
  620. mVideoSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
  621. }
  622. public void setBtnSub(Boolean state) {
  623. if (mMediaPlayer != null) {
  624. if (state) {
  625. btSubTitre.setBackgroundResource(R.drawable.bg_rectangle_radius_white_on);
  626. btSubTitre.setTextColor(getApplication().getResources().getColor(R.color.black));
  627. //Log.d(LOG_TAG, "scanSetBtnSub >0 : " + " mCurrentSpuTrack = " + Integer.toString(mCurrentSpuTrack) + " ENABLE_SUBTITLES=" + Boolean.toString(ENABLE_SUBTITLES) + " btnNoActive=" + Boolean.toString(btnNoActive));
  628. } else {
  629. btSubTitre.setBackgroundResource(R.drawable.bg_rectangle_radius_white);
  630. btSubTitre.setTextColor(getApplication().getResources().getColor(R.color.white));
  631. // Log.d(LOG_TAG, "scanSetBtnSub else : " + " mCurrentSpuTrack = " + Integer.toString(mCurrentSpuTrack) + " ENABLE_SUBTITLES=" + Boolean.toString(ENABLE_SUBTITLES) + " btnNoActive=" + Boolean.toString(btnNoActive));
  632. }
  633. }
  634. }
  635. public void showMenu(Boolean show) {
  636. if (show) {
  637. LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
  638. channelRecycler.setLayoutManager(layoutManager);
  639. channelRecycler.setAdapter(new ChannelRecyclerAdapter(getApplicationContext(), channels));
  640. channelPlace.setVisibility(View.VISIBLE);
  641. // programPlace.setVisibility(View.VISIBLE);
  642. btExitTV.setVisibility(View.VISIBLE);
  643. placeSub.setVisibility(View.VISIBLE);
  644. btSubTitreWidth = llSub.getWidth();
  645. btSubTitreHeight = llSub.getHeight();
  646. getWindow().getDecorView().setSystemUiVisibility(
  647. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  648. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  649. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  650. | View.SYSTEM_UI_FLAG_FULLSCREEN
  651. | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  652. );
  653. // is_menu = true;
  654. } else {
  655. channelPlace.setVisibility(View.INVISIBLE);
  656. // programPlace.setVisibility(View.INVISIBLE);
  657. btExitTV.setVisibility(View.INVISIBLE);
  658. placeSub.setVisibility(View.INVISIBLE);
  659. btSubTitreWidth = 0;
  660. btSubTitreHeight = 0;
  661. getWindow().getDecorView().setSystemUiVisibility(
  662. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  663. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  664. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  665. | View.SYSTEM_UI_FLAG_FULLSCREEN
  666. | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
  667. );
  668. // is_menu = false;
  669. }
  670. }
  671. @Override
  672. public void onClick(View v) {
  673. switch (v.getId()) {
  674. case R.id.btExitTV:
  675. finish();
  676. break;
  677. case R.id.btSubTitre:
  678. setScanTrack();
  679. if (btnIsSingle && (ENABLE_SUBTITLES == false )) {
  680. setBtnSub(true);
  681. setOnOffSingleSub(idTrackOn);
  682. ENABLE_SUBTITLES = true;
  683. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, ENABLE_SUBTITLES);
  684. checkBtnSub =1;
  685. saveChannelState(mFilePatch, mCurrentSpuTrack);
  686. // Log.d(LOG_TAG, "btnIsSingle false " + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack) + " ENABLE_SUBTITLES=" + Boolean.toString(ENABLE_SUBTITLES));
  687. break;
  688. } else {
  689. if (btnIsSingle && (ENABLE_SUBTITLES == true)) {
  690. setBtnSub(false);
  691. setOnOffSingleSub(idtrackOff);
  692. ENABLE_SUBTITLES = false;
  693. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, ENABLE_SUBTITLES);
  694. checkBtnSub =0;
  695. saveChannelState(mFilePatch, mCurrentSpuTrack);
  696. // Log.d(LOG_TAG, "btnIsSingle true " + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack) + " ENABLE_SUBTITLES=" + Boolean.toString(ENABLE_SUBTITLES));
  697. break;
  698. }
  699. }
  700. if (btnIsAll) {
  701. onAudioSubClick(v);
  702. //Log.d(LOG_TAG,"btnIsAll: "+" mCurrentSpuTrack "+ Integer.toString(mCurrentSpuTrack)+ " ENABLE_SUBTITLES="+ Boolean.toString(ENABLE_SUBTITLES));
  703. break;
  704. }
  705. if (btnNoActive) {
  706. //onAudioSubClick(v);
  707. mCurrentSpuTrack = -2;
  708. mMediaPlayer.setSpuTrack(mCurrentSpuTrack);
  709. saveChannelState(mFilePatch, mCurrentSpuTrack);
  710. setBtnSub(false);
  711. //ENABLE_SUBTITLES = false;
  712. Toast.makeText(this, getResources().getText(invalid_subtitles), Toast.LENGTH_LONG).show();
  713. //Log.d(LOG_TAG,"btnNoActive: "+" mCurrentSpuTrack "+Integer.toString(mCurrentSpuTrack)+ " ENABLE_SUBTITLES="+ Boolean.toString(ENABLE_SUBTITLES));
  714. break;
  715. }
  716. // case R.id.bt_en:
  717. /* // MyApp.setLocaleEn(RtspPlayerActivity.this);
  718. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.LOCALE, "EN");
  719. finish();
  720. startActivity(getIntent());
  721. setLanguege("EN");
  722. updateUi();*/
  723. // break;
  724. // case R.id.bt_de:
  725. /* //MyApp.setLocaleDe(RtspPlayerActivity.this);
  726. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.LOCALE, "DE");
  727. finish();
  728. startActivity(getIntent());
  729. setLanguege("DE");
  730. updateUi();*/
  731. // break;
  732. }
  733. }
  734. @Override
  735. public boolean onTouch(View v, MotionEvent event) {
  736. int x = (int) event.getX();
  737. int y = (int) event.getY();
  738. Log.d(LOG_TAG, "onTouch" + " x=" + x + " y=" + y);
  739. switch (event.getAction()) {
  740. case MotionEvent.ACTION_UP: // нажатие
  741. if (y < (ScreenHeight - btSubTitreHeight - 100)) {
  742. if(!mChannelType.equals("radio")) {
  743. if (!is_menu) {
  744. //if(!mChannelType.equals("radio")){
  745. setScanTrack();
  746. // }
  747. showMenu(true);
  748. is_menu = true;
  749. } else {
  750. btnIsSingle = false;
  751. btnIsAll = false;
  752. btnNoActive = false;
  753. showMenu(false);
  754. is_menu = false;
  755. }
  756. }else{
  757. showMenu(true);
  758. is_menu = true;
  759. }
  760. }
  761. break;
  762. }
  763. return true;
  764. }
  765. public void setScanTrack() {
  766. MediaPlayer.TrackDescription[] tracks = mMediaPlayer.getSpuTracks();
  767. scanTrack(tracks);
  768. Log.d(LOG_TAG, " nameList =" + nameList+" tracks =" + tracks+" mMediaPlayer =" + mMediaPlayer);
  769. if (nameList == null) {
  770. Log.d(LOG_TAG, "Нет субтитров" + " btnNoActive=" + Boolean.toString(btnNoActive));
  771. btnNoActive = true;
  772. btnIsSingle = false;
  773. btnIsAll = false;
  774. setBtnSub(false);
  775. }
  776. if ((nameList != null) && (nameList.length == 2)) {
  777. btnIsSingle = true;
  778. btnIsAll = false;
  779. btnNoActive = false;
  780. idTrackOn = idList[1];
  781. idtrackOff = idList[0];
  782. switch (checkBtnSub) {
  783. case 0:
  784. setOnOffSingleSub(idtrackOff);
  785. saveChannelState(mFilePatch, idtrackOff);
  786. setBtnSub(false);
  787. break;
  788. case 1:
  789. int saveNumIdTrack=readChannelState(mFilePatch);
  790. if (saveNumIdTrack<0){
  791. setOnOffSingleSub(idTrackOn);
  792. saveChannelState(mFilePatch, idTrackOn);
  793. setBtnSub(true);
  794. }else{
  795. if(saveNumIdTrack>0){
  796. setOnOffSingleSub(saveNumIdTrack);
  797. setBtnSub(true);
  798. }
  799. }
  800. break;
  801. }
  802. //Log.d(LOG_TAG, "1 субтитров" + " btnNoActive=" + Boolean.toString(btnNoActive));
  803. }
  804. if ((nameList != null) && (nameList.length > 2)) {
  805. btnIsSingle = false;
  806. btnIsAll = true;
  807. btnNoActive = false;
  808. // Log.d(LOG_TAG, ">1 субтитров" + " btnNoActive=" + Boolean.toString(btnNoActive));
  809. }
  810. handler.removeCallbacks(t);
  811. }
  812. public void setOnOffSingleSub(int idTrack) {
  813. MediaPlayer.TrackDescription[] tracks = mMediaPlayer.getSpuTracks();
  814. mCurrentSpuTrack = -2;
  815. for (MediaPlayer.TrackDescription track : tracks) {
  816. if (idTrack == track.id) {
  817. mCurrentSpuTrack = idTrack;
  818. break;
  819. }
  820. }
  821. mMediaPlayer.setSpuTrack(mCurrentSpuTrack);
  822. //Log.d(LOG_TAG, "setOnOffSingleSub " + " idTrack " + Integer.toString(idTrack) + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack));
  823. }
  824. public void saveChannelState(String uri, Integer currentSub) {
  825. channelStateInfo.put(uri, String.valueOf(currentSub));
  826. PreferencesUtils.saveChannelStateInfo(getApplicationContext(), CHANNEL_INFO, channelStateInfo);
  827. }
  828. public int readChannelState(String uri) {
  829. int num = -2;
  830. String nums = PreferencesUtils.readChannelStateInfo(getApplicationContext(), CHANNEL_INFO, uri, "-2");
  831. if (nums != null) {
  832. num = Integer.valueOf(nums);
  833. }
  834. return num;
  835. }
  836. private class SubtitlesGetTask extends AsyncTask<String, Void, List<String>> {
  837. @Override
  838. protected List<String> doInBackground(String... strings) {
  839. final String subtitleList_serialized = strings[0];
  840. List<String> prefsList = new ArrayList<>();
  841. if (subtitleList_serialized != null) {
  842. final ByteArrayInputStream bis = new ByteArrayInputStream(subtitleList_serialized.getBytes());
  843. ObjectInputStream ois = null;
  844. try {
  845. ois = new ObjectInputStream(bis);
  846. prefsList = (List<String>) ois.readObject();
  847. } catch (InterruptedIOException ignored) {
  848. return prefsList; /* Task is cancelled */
  849. } catch (ClassNotFoundException | IOException ignored) {
  850. } finally {
  851. close(ois);
  852. }
  853. }
  854. return prefsList;
  855. }
  856. @Override
  857. protected void onPostExecute(List<String> prefsList) {
  858. // Add any selected subtitle file from the file picker
  859. if (prefsList.size() > 0) {
  860. for (String file : prefsList) {
  861. synchronized (mSubtitleSelectedFiles) {
  862. if (!mSubtitleSelectedFiles.contains(file))
  863. mSubtitleSelectedFiles.add(file);
  864. }
  865. //Log.d(LOG_TAG, "Adding user-selected subtitle " + file);
  866. mMediaPlayer.addSlave(Media.Slave.Type.Subtitle, file, true);
  867. //Log.d(LOG_TAG, "SubtitlesGetTask: =" + " mMediaPlayer.addSlave " + file);
  868. //mMediaPlayer.addSubtitleTrack(file, true);
  869. }
  870. }
  871. mSubtitlesGetTask = null;
  872. }
  873. @Override
  874. protected void onCancelled() {
  875. mSubtitlesGetTask = null;
  876. }
  877. }
  878. public boolean close(Closeable closeable) {
  879. if (closeable != null)
  880. try {
  881. closeable.close();
  882. return true;
  883. } catch (IOException e) {}
  884. return false;
  885. }
  886. public void getSubtitles() {
  887. if (mSubtitlesGetTask != null || mMediaPlayer == null)
  888. return;
  889. final String subtitleList_serialized = PreferencesUtils.readStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO_SUBTITLE_FILES,null);
  890. mSubtitlesGetTask = new SubtitlesGetTask();
  891. mSubtitlesGetTask.execute(subtitleList_serialized);
  892. }
  893. public void onAudioSubClick(View v) {
  894. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  895. View customView = inflater.inflate(R.layout.rtsp_customdialog,null);
  896. final PopupMenu popupMenu = new PopupMenu(this, btSubTitre, Gravity.CENTER,0,R.style.MyPopapTheme);
  897. final Menu menu = popupMenu.getMenu();
  898. popupMenu.getMenuInflater().inflate(R.menu.audiosub_tracks, menu);
  899. menu.findItem(R.id.video_menu_audio_track).setTitle(track_audio);
  900. menu.findItem(R.id.video_menu_subtitles).setTitle(subtitles);
  901. menu.findItem(R.id.video_menu_audio_track).setEnabled(mMediaPlayer.getAudioTracksCount() >= 1);
  902. menu.findItem(R.id.video_menu_subtitles).setEnabled(mMediaPlayer.getSpuTracksCount() > 0);
  903. popupMenu.setOnMenuItemClickListener(item -> {
  904. switch (item.getItemId()) {
  905. case R.id.video_menu_audio_track:
  906. selectAudioTrack();
  907. return true;
  908. case R.id.video_menu_subtitles:
  909. selectSubtitles();
  910. return true;
  911. default:
  912. return false;
  913. }
  914. });
  915. popupMenu.show();
  916. }
  917. private void selectAudioTrack() {
  918. setESTrackLists();
  919. selectTrack(mAudioTracksList, mMediaPlayer.getAudioTrack(), track_audio,
  920. new TrackSelectedListener() {
  921. @Override
  922. public void onTrackSelected(int trackID) {
  923. if (trackID < -1 || mMediaPlayer == null)
  924. return;
  925. mMediaPlayer.setAudioTrack(trackID);
  926. }
  927. });
  928. }
  929. private void selectSubtitles() {
  930. setESTrackLists();
  931. selectTrack(mSubtitleTracksList, mMediaPlayer.getSpuTrack(), track_text,
  932. new TrackSelectedListener() {
  933. @Override
  934. public void onTrackSelected(int trackID) {
  935. if (trackID < -1 || mMediaPlayer == null)
  936. return;
  937. mMediaPlayer.setSpuTrack(trackID);
  938. mCurrentSpuTrack= trackID;
  939. saveChannelState(mFilePatch, mCurrentSpuTrack);
  940. setBtnSub(mCurrentSpuTrack>2? true:false);
  941. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, mCurrentSpuTrack>2? true:false);
  942. }
  943. });
  944. Log.d(LOG_TAG,"selectTrack: "+ " mCurrentSpuTrack "+Integer.toString(mCurrentSpuTrack)+ " ENABLE_SUBTITLES="+ Boolean.toString(ENABLE_SUBTITLES));
  945. }
  946. private void setESTrackLists() {
  947. if (mAudioTracksList == null && mMediaPlayer.getAudioTracksCount() > 0)
  948. mAudioTracksList = mMediaPlayer.getAudioTracks();
  949. if (mSubtitleTracksList == null && mMediaPlayer.getSpuTracksCount() > 0)
  950. mSubtitleTracksList = mMediaPlayer.getSpuTracks();
  951. }
  952. private void invalidateESTracks(int type) {
  953. switch (type) {
  954. case Media.Track.Type.Audio:
  955. mAudioTracksList = null;
  956. break;
  957. case Media.Track.Type.Text:
  958. mSubtitleTracksList = null;
  959. break;
  960. }
  961. }
  962. private void setESTracks() {
  963. if (mLastAudioTrack >= -1) {
  964. mMediaPlayer.setAudioTrack(mLastAudioTrack);
  965. mLastAudioTrack = -2;
  966. }
  967. }
  968. void reping() {
  969. Log.d(LOG_TAG,"reping");
  970. if((mMediaPlayer!=null)&&(mUri!=null)) {
  971. mMediaPlayer.stop();
  972. mMediaPlayer.getVLCVout().detachViews();
  973. onStart();
  974. flagsStart(AFTER_REPING);
  975. }
  976. }
  977. void getESAdded() {
  978. Log.d(LOG_TAG,"getESAdded");
  979. media = mMediaPlayer.getMedia();
  980. setESTrackLists();
  981. int spuTrack = mMediaPlayer.getSpuTracksCount(); /*media.get(MediaWrapper.META_SUBTITLE_TRACK);*/
  982. if (spuTrack != 0 || mCurrentSpuTrack != -2) {
  983. mMediaPlayer.setSpuTrack( mCurrentSpuTrack );
  984. Log.d(LOG_TAG, "getESAdded =" + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack));
  985. }
  986. }
  987. @Override
  988. protected void onDestroy() {
  989. super.onDestroy();
  990. Log.d(LOG_TAG, "onDestroy" );
  991. mMediaPlayer.release();
  992. mLibVLC.release();
  993. if(r!=null){
  994. handler.removeCallbacks(r);
  995. }
  996. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, checkBtnSub==0?false:true);
  997. }
  998. @Override
  999. protected void onResume() {
  1000. super.onResume();
  1001. Log.d(LOG_TAG, "onResume" );
  1002. handler.postDelayed(r, timer);
  1003. //Log.d(LOG_TAG, "onResume is_menu =" + Boolean.toString(is_menu) + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack));
  1004. checkBtnSub =PreferencesUtils.readBoolSharedSetting(getApplicationContext(), PreferencesUtils.CHECK_BTN_SUB, false)? 1: 0;
  1005. mVideoView.setOnTouchListener(this);
  1006. }
  1007. @Override
  1008. protected void onPause() {
  1009. super.onPause();
  1010. Log.d(LOG_TAG, "onPause" );
  1011. saveChannelInPrefs(mFilePatch);
  1012. if(!mChannelType.equals("radio")) {
  1013. if (r != null) {
  1014. handler.removeCallbacks(r);
  1015. }
  1016. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, checkBtnSub == 0 ? false : true);
  1017. String subtitleList_serialized = null;
  1018. synchronized (mSubtitleSelectedFiles) {
  1019. if (mSubtitleSelectedFiles.size() > 0) {
  1020. //Log.d(LOG_TAG, "Saving selected subtitle files");
  1021. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  1022. try {
  1023. ObjectOutputStream oos = new ObjectOutputStream(bos);
  1024. oos.writeObject(mSubtitleSelectedFiles);
  1025. subtitleList_serialized = bos.toString();
  1026. } catch (IOException ignored) {
  1027. }
  1028. }
  1029. }
  1030. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO_SUBTITLE_FILES, subtitleList_serialized);
  1031. if (mSubtitlesGetTask != null)
  1032. mSubtitlesGetTask.cancel(true);
  1033. if (mOnLayoutChangeListener != null) {
  1034. mVideoSurfaceFrame.removeOnLayoutChangeListener(mOnLayoutChangeListener);
  1035. mOnLayoutChangeListener = null;
  1036. }
  1037. // Log.d(LOG_TAG, "onPause is_menu =" + Boolean.toString(is_menu) + " subtitleList_serialized = " + subtitleList_serialized + " mCurrentSpuTrack " + Integer.toString(mCurrentSpuTrack));
  1038. }//если не радио
  1039. mMediaPlayer.stop();
  1040. mMediaPlayer.getVLCVout().detachViews();
  1041. // }//если не радио
  1042. }
  1043. @Override
  1044. protected void onStop() {
  1045. super.onStop();
  1046. Log.d(LOG_TAG, "onStop" );
  1047. saveChannelInPrefs(mFilePatch);
  1048. if (r != null) {
  1049. handler.removeCallbacks(r);
  1050. }
  1051. if(!mChannelType.equals("radio")) {
  1052. PreferencesUtils.saveBoolSharedSetting(getApplicationContext(), CHECK_BTN_SUB, checkBtnSub == 0 ? false : true);
  1053. String subtitleList_serialized = null;
  1054. synchronized (mSubtitleSelectedFiles) {
  1055. if (mSubtitleSelectedFiles.size() > 0) {
  1056. //Log.d(LOG_TAG, "Saving selected subtitle files");
  1057. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  1058. try {
  1059. ObjectOutputStream oos = new ObjectOutputStream(bos);
  1060. oos.writeObject(mSubtitleSelectedFiles);
  1061. subtitleList_serialized = bos.toString();
  1062. } catch (IOException ignored) {
  1063. }
  1064. }
  1065. }
  1066. PreferencesUtils.saveStrSharedSetting(getApplicationContext(), PreferencesUtils.VIDEO

Large files files are truncated, but you can click here to view the full file