Commit b1f4adc7 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 56a54c9a
...@@ -80,6 +80,6 @@ public class RingtoneHelper { ...@@ -80,6 +80,6 @@ public class RingtoneHelper {
} }
RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri);
ToastUtil.show(context,"设置来电铃声成功!"); // ToastUtil.show(context,"设置来电铃声成功!");
} }
} }
package com.mints.goodmoney.ui.activitys package com.mints.goodmoney.ui.activitys
import android.Manifest import android.Manifest
import android.media.MediaPlayer
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import cn.jzvd.Jzvd import android.widget.VideoView
import com.downloader.Error import com.downloader.Error
import com.downloader.OnDownloadListener import com.downloader.OnDownloadListener
import com.downloader.PRDownloader import com.downloader.PRDownloader
...@@ -41,6 +42,7 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView { ...@@ -41,6 +42,7 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView {
private var downloadId: Int = -1//vedio下载id private var downloadId: Int = -1//vedio下载id
private var downloadVedioSucFlag = false// 下载视频成功 private var downloadVedioSucFlag = false// 下载视频成功
private var vedioName = ""
override fun getContentViewLayoutID() = R.layout.activity_kyl_vedio override fun getContentViewLayoutID() = R.layout.activity_kyl_vedio
...@@ -65,41 +67,28 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView { ...@@ -65,41 +67,28 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView {
} }
private fun loadVedio(vedioUrl: String) { private fun loadVedio(vedioUrl: String) {
jzvdStd?.setUp(vedioUrl, "") jzvdStd?.setOnPreparedListener { mp: MediaPlayer ->
jzvdStd?.startVideo() mp.start()
// jzvdStd.setVedioRestart(false) mp.isLooping = true
// jzvdStd.setJzVedioStatusListener(object : JZVideoPlayerStandardLoopVideo.JZVedioStatusListener {
// override fun jzVedioPlaying() {
// }
// })
}
override fun onBackPressed() {
if (Jzvd.backPress()) {
return
} }
super.onBackPressed() jzvdStd?.setVideoPath(vedioUrl)
jzvdStd?.start()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (!isFinishing()) { jzvdStd.resume()
Jzvd.goOnPlayOnResume()
}
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
Jzvd.goOnPlayOnPause() jzvdStd.pause()
} }
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
Jzvd.releaseAllVideos()
jzvdStd?.removeAllViews()
if (downloadId != -1) { if (downloadId != -1) {
PRDownloader.cancel(downloadId) PRDownloader.cancel(downloadId)
} }
...@@ -123,41 +112,32 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView { ...@@ -123,41 +112,32 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView {
.subscribe { granted: Boolean -> .subscribe { granted: Boolean ->
if (granted) { if (granted) {
downloadVedioToCacheFile() downloadVedioToCacheFile()
awardVedio()
} else { } else {
showMissingPermissionDialog("存储") showMissingPermissionDialog("存储")
} }
} }
// awardVedio()
} }
} }
} }
private fun downloadVedioToCacheFile() { private fun downloadVedioToCacheFile() {
showLoading("加载中...") downloadVedioSucFlag = false
var vedioPath = "" var vedioPath = ""
try { try {
vedioPath = getExternalFilesDir(null)!!.absolutePath + "/video/" vedioPath = getExternalFilesDir(null)!!.absolutePath + "/video/"
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
vedioPath = filesDir.absolutePath + "/video/" vedioPath = filesDir.absolutePath + "/video/"
} }
val vedioName = MD5.GetMD5Code(System.currentTimeMillis().toString() + UserManager.getInstance().userID + vedioUrl) + ".mp4" vedioName = MD5.GetMD5Code(System.currentTimeMillis().toString() + UserManager.getInstance().userID + vedioUrl) + ".mp4"
downloadId = PRDownloader.download(vedioUrl, vedioPath, vedioName) downloadId = PRDownloader.download(vedioUrl, vedioPath, vedioName)
.build() .build()
.start(object : OnDownloadListener { .start(object : OnDownloadListener {
override fun onDownloadComplete() { override fun onDownloadComplete() {
runOnUiThread { downloadVedioSucFlag = true
hideLoading()
// downloadVedioSucFlag = true
val vedioName = vedioPath + vedioName
DetailActivity.startSelf(this@KylVedioActivity, vedioName)
}
} }
override fun onError(error: Error) { override fun onError(error: Error) {
runOnUiThread {
showToast("加载失败")
hideLoading()
}
} }
}) })
} }
...@@ -219,10 +199,7 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView { ...@@ -219,10 +199,7 @@ class KylVedioActivity : BaseActivity(), View.OnClickListener, KylVedioView {
private fun vedioAdingSuccess(adType: String) { private fun vedioAdingSuccess(adType: String) {
if (downloadVedioSucFlag) { if (downloadVedioSucFlag) {
try { DetailActivity.startSelf(this@KylVedioActivity, vedioName)
} catch (e: Exception) {
e.printStackTrace()
}
} }
} }
} }
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<TextView <TextView
android:visibility="gone"
android:id="@+id/set_show_tv" android:id="@+id/set_show_tv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black"> android:background="@color/black">
<com.mints.goodmoney.ui.widgets.JZVideoPlayerStandardLoopVideo <com.mints.goodmoney.call.widget.CustomVideoView
android:id="@+id/jzvdStd" android:id="@+id/jzvdStd"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment