-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9e57767
Showing
57 changed files
with
5,278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.2" | ||
defaultConfig { | ||
applicationId "jaygoo.m3u8downloader" | ||
minSdkVersion 16 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
multiDexEnabled true | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:26.+' | ||
compile 'com.android.support:design:26.+' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.karumi:dexter:4.2.0' | ||
compile project(path: ':library') | ||
compile 'com.shuyu:GSYVideoPlayer:2.1.1' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/mac/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="jaygoo.m3u8downloader"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".FullScreenActivity" | ||
android:theme="@style/FullScreenTheme" | ||
android:windowSoftInputMode="stateAlwaysHidden"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
99 changes: 99 additions & 0 deletions
99
app/src/main/java/jaygoo/m3u8downloader/FullScreenActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package jaygoo.m3u8downloader; | ||
|
||
import android.app.Activity; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.shuyu.gsyvideoplayer.GSYVideoManager; | ||
import com.shuyu.gsyvideoplayer.model.VideoOptionModel; | ||
import com.shuyu.gsyvideoplayer.utils.OrientationUtils; | ||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer; | ||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jaygoo.library.m3u8downloader.server.M3u8Server; | ||
import jaygoo.library.m3u8downloader.utils.M3U8Log; | ||
import tv.danmaku.ijk.media.player.IjkMediaPlayer; | ||
|
||
/** | ||
* ================================================ | ||
* 作 者:JayGoo | ||
* 版 本: | ||
* 创建日期:2017/11/21 | ||
* 描 述: | ||
* ================================================ | ||
*/ | ||
public class FullScreenActivity extends Activity{ | ||
|
||
private StandardGSYVideoPlayer videoPlayer; | ||
private OrientationUtils orientationUtils; | ||
private String encryptKey = "63F06F99D823D33AAB89A0A93DECFEE0"; | ||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fullscreen); | ||
videoPlayer = (StandardGSYVideoPlayer)findViewById(R.id.videoView); | ||
orientationUtils = new OrientationUtils(this, videoPlayer); | ||
orientationUtils.resolveByClick(); | ||
videoPlayer.startWindowFullscreen(this,false,false); | ||
List<VideoOptionModel> optionModels = new ArrayList<>(); | ||
optionModels.add(new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, | ||
"protocol_whitelist", "crypto,file,http,https,tcp,tls,udp")); | ||
GSYVideoManager.instance().setOptionModelList(optionModels); | ||
String url = null; | ||
Bundle bundle = getIntent().getExtras(); | ||
if (bundle != null){ | ||
url = bundle.getString("M3U8_URL"); | ||
} | ||
Uri uri = Uri.parse(url); | ||
M3U8Log.d("uri: "+uri); | ||
String scheme = uri.getScheme(); | ||
M3U8Log.d("scheme: "+scheme); | ||
String mVideoSource; | ||
if (null != scheme) { | ||
mVideoSource = uri.toString(); | ||
} else { | ||
mVideoSource = uri.getPath(); | ||
} | ||
M3U8Log.d("mVideoSource: "+mVideoSource); | ||
String mSource = M3u8Server.createLocalUrl(mVideoSource); | ||
M3U8Log.d("mSource: "+mSource); | ||
M3u8Server.execute(); | ||
videoPlayer.setUp(mSource,false,""); | ||
videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
finish(); | ||
} | ||
}); | ||
videoPlayer.startPlayLogic(); | ||
|
||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
M3u8Server.onResume(encryptKey); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
M3u8Server.onPause(encryptKey); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
M3u8Server.finish(); | ||
//释放所有 | ||
videoPlayer.getCurrentPlayer().release(); | ||
GSYVideoPlayer.releaseAllVideos(); | ||
videoPlayer.setStandardVideoAllCallBack(null); | ||
} | ||
} |
179 changes: 179 additions & 0 deletions
179
app/src/main/java/jaygoo/m3u8downloader/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package jaygoo.m3u8downloader; | ||
|
||
import android.Manifest; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ListView; | ||
import android.widget.Toast; | ||
|
||
import com.karumi.dexter.Dexter; | ||
import com.karumi.dexter.MultiplePermissionsReport; | ||
import com.karumi.dexter.PermissionToken; | ||
import com.karumi.dexter.listener.PermissionRequest; | ||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener; | ||
|
||
import java.util.List; | ||
|
||
import jaygoo.library.m3u8downloader.M3U8Downloader; | ||
import jaygoo.library.m3u8downloader.M3U8DownloaderConfig; | ||
import jaygoo.library.m3u8downloader.OnM3U8DownloadListener; | ||
import jaygoo.library.m3u8downloader.bean.M3U8Task; | ||
import jaygoo.library.m3u8downloader.utils.AES128Utils; | ||
import jaygoo.library.m3u8downloader.utils.M3U8Log; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
static final String[] PERMISSIONS = new String[]{ | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.READ_EXTERNAL_STORAGE, | ||
}; | ||
|
||
M3U8Task[] taskList = new M3U8Task[6]; | ||
private VideoListAdapter adapter; | ||
private String dirPath; | ||
private String encryptKey = "63F06F99D823D33AAB89A0A93DECFEE0"; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
requestAppPermissions(); | ||
try { | ||
M3U8Log.d("AES BASE64 Random Key:"+AES128Utils.getAESKey() ); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
private void initView() { | ||
dirPath = StorageUtils.getCacheDirectory(this).getPath()+"/m3u8Downloader"; | ||
//common config ! | ||
M3U8DownloaderConfig | ||
.build(getApplicationContext()) | ||
.setSaveDir(dirPath) | ||
.setDebugMode(true) | ||
; | ||
|
||
// add listener | ||
M3U8Downloader.getInstance().setOnM3U8DownloadListener(onM3U8DownloadListener); | ||
M3U8Downloader.getInstance().setEncryptKey(encryptKey); | ||
initData(); | ||
adapter = new VideoListAdapter(this, R.layout.list_item, taskList); | ||
ListView listView = (ListView) findViewById(R.id.list_view); | ||
listView.setAdapter(adapter); | ||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||
String url = taskList[position].getUrl(); | ||
if (M3U8Downloader.getInstance().checkM3U8IsExist(url)){ | ||
Toast.makeText(getApplicationContext(),"本地文件已下载,正在播放中!!!", Toast.LENGTH_SHORT).show(); | ||
Intent intent = new Intent(MainActivity.this,FullScreenActivity.class); | ||
intent.putExtra("M3U8_URL",M3U8Downloader.getInstance().getM3U8Path(url)); | ||
startActivity(intent); | ||
}else { | ||
if (M3U8Downloader.getInstance().isTaskDownloading(url)) { | ||
M3U8Downloader.getInstance().pause(url); | ||
} else { | ||
M3U8Downloader.getInstance().download(url); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void initData(){ | ||
// MUtils.clearDir(new File(dirPath)); | ||
M3U8Task bean0 = new M3U8Task("https://media6.smartstudy.com/52/9c/10732/4/dest.m3u8"); | ||
M3U8Task bean1 = new M3U8Task("https://media6.smartstudy.com/b2/75/2475/4/dest.m3u8"); | ||
M3U8Task bean2 = new M3U8Task("https://media6.smartstudy.com/ae/07/3997/2/dest.m3u8"); | ||
M3U8Task bean3 = new M3U8Task("http://hls.ciguang.tv/hdtv/video.m3u8"); | ||
M3U8Task bean4 = new M3U8Task("http://hcjs2ra2rytd8v8np1q.exp.bcevod.com/mda-hegtjx8n5e8jt9zv/mda-hegtjx8n5e8jt9zv.m3u8"); | ||
M3U8Task bean5 = new M3U8Task("https://media6.smartstudy.com/55/34/2542/4/dest.m3u8"); | ||
taskList[0] = bean0; | ||
taskList[1] = bean1; | ||
taskList[2] = bean2; | ||
taskList[3] = bean3; | ||
taskList[4] = bean4; | ||
taskList[5] = bean5; | ||
} | ||
|
||
private OnM3U8DownloadListener onM3U8DownloadListener = new OnM3U8DownloadListener() { | ||
|
||
@Override | ||
public void onDownloadSuccess(M3U8Task task) { | ||
super.onDownloadSuccess(task); | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
|
||
@Override | ||
public void onDownloadPending(M3U8Task task) { | ||
super.onDownloadPending(task); | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
|
||
@Override | ||
public void onDownloadPause(M3U8Task task) { | ||
super.onDownloadPause(task); | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
|
||
@Override | ||
public void onDownloadProgress(final M3U8Task task) { | ||
super.onDownloadProgress(task); | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
}); | ||
|
||
} | ||
|
||
@Override | ||
public void onDownloadPrepare(final M3U8Task task) { | ||
super.onDownloadPrepare(task); | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onDownloadError(M3U8Task task, Throwable errorMsg) { | ||
super.onDownloadError(task, errorMsg); | ||
adapter.notifyChanged(taskList, task); | ||
} | ||
|
||
@Override | ||
public void onAllTaskComplete() { | ||
super.onAllTaskComplete(); | ||
Toast.makeText(getApplicationContext(),"文件全部下载完成!!!!", Toast.LENGTH_LONG).show(); | ||
|
||
} | ||
}; | ||
|
||
private void requestAppPermissions() { | ||
Dexter.withActivity(this) | ||
.withPermissions(PERMISSIONS) | ||
.withListener(new MultiplePermissionsListener() { | ||
@Override | ||
public void onPermissionsChecked(MultiplePermissionsReport report) { | ||
if (report.areAllPermissionsGranted()) { | ||
initView(); | ||
Toast.makeText(getApplicationContext(),"权限获取成功",Toast.LENGTH_LONG).show(); | ||
}else { | ||
Toast.makeText(getApplicationContext(),"权限获取失败",Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) { | ||
} | ||
}) | ||
.check(); | ||
} | ||
} |
Oops, something went wrong.