Commit cf4cc1ca authored by jyx's avatar jyx

添加喜马拉雅SDK

parent 8b5dd9be
......@@ -250,11 +250,18 @@ dependencies {
implementation(name: 'okgo-2.1', ext: 'aar')
implementation(name: 'scenemodule-2.1', ext: 'aar')
implementation(name: 'scenead-2.1', ext: 'aar')
implementation 'com.just.agentweb:agentweb:4.1.2'
// implementation 'com.squareup.okio:okio:1.13.0'
// implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
// 喜马拉雅
// v4包
implementation 'com.android.support:support-v4:28.0.0'
implementation files('libs/TingPhoneOpenSDK_7.4.1.jar')
implementation files('libs/XmDownload_2.0.jar')
implementation files('libs/XmlyOAuth2SDK_V2.0.jar')
// testImplementation 'junit:junit:4.13'
// androidTestImplementation 'androidx.test.ext:junit:1.1.2'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
......
......@@ -109,11 +109,7 @@
android:name=".ui.activitys.SplashYlhActivity"
android:screenOrientation="portrait"
android:theme="@style/NormalSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activitys.MainActivity"
......@@ -193,6 +189,15 @@
<activity
android:name=".ui.activitys.DhGameActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activitys.XmlyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".service.UpdateService"
......@@ -203,6 +208,13 @@
android:enabled="true"
android:exported="false" />
<!-- 喜马拉雅播放器 -->
<service
android:name="com.ximalaya.ting.android.opensdk.player.service.XmPlayerService"
android:exported="true"
android:process=":player" />
<!-- JPUSH 用户自定义的广播接收器 -->
<receiver
android:name="com.mints.goodmoney.service.JpushReceiver"
......
......@@ -7,7 +7,6 @@ import android.content.Intent
import cn.jpush.android.api.BasicPushNotificationBuilder
import cn.jpush.android.api.JPushInterface
import com.mints.goodmoney.manager.BxmManager.initBxm
import com.mints.goodmoney.manager.ZhangyueManager
import com.mints.library.utils.CommonUtils
import com.mob.MobSDK
import com.orhanobut.logger.AndroidLogAdapter
......@@ -17,6 +16,9 @@ import com.orhanobut.logger.PrettyFormatStrategy
import com.tendcloud.tenddata.TCAgent
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
import com.ximalaya.ting.android.opensdk.constants.ConstantsOpenSdk
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest
/**
* 子线程初始化SDK
......@@ -77,6 +79,15 @@ class InitAppService : IntentService("InitializeService") {
// 变现猫
initBxm(this.application)
// 喜马拉雅
val mXimalaya = CommonRequest.getInstanse()
val mAppSecret = "db3cb9e3ec5943f4987e78ddc5aec728"
val mAppKey = "ff71a11162f20808f9f349452dd9e141"
mXimalaya.setAppkey(mAppKey)
mXimalaya.setPackid("com.mints.goodmoney")
mXimalaya.init(this, mAppSecret)
ConstantsOpenSdk.isDebug = true
}
/**
......
package com.mints.goodmoney.ui.activitys
import android.util.Log
import android.view.View
import android.widget.Toast
import com.fly.scenemodule.util.GsonUtils
import com.mints.goodmoney.R
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.utils.LogUtil
import com.ximalaya.ting.android.opensdk.constants.DTransferConstants
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack
import com.ximalaya.ting.android.opensdk.model.PlayableModel
import com.ximalaya.ting.android.opensdk.model.album.AlbumList
import com.ximalaya.ting.android.opensdk.model.category.CategoryList
import com.ximalaya.ting.android.opensdk.model.live.radio.Radio
import com.ximalaya.ting.android.opensdk.model.live.schedule.Schedule
import com.ximalaya.ting.android.opensdk.model.track.Track
import com.ximalaya.ting.android.opensdk.model.track.TrackList
import com.ximalaya.ting.android.opensdk.player.XmPlayerManager
import com.ximalaya.ting.android.opensdk.player.service.IXmPlayerStatusListener
import com.ximalaya.ting.android.opensdk.player.service.XmPlayListControl
import com.ximalaya.ting.android.opensdk.player.service.XmPlayerException
import kotlinx.android.synthetic.main.activity_xmly_test.*
import kotlinx.android.synthetic.main.header_layout.*
/**
* 描述:关于我们
* 作者:孟崔广
* 时间:2020/9/23 18:39
*/
class XmlyActivity : BaseActivity(), View.OnClickListener {
private val TAG = XmlyActivity::class.java.simpleName
private var mCategoryList: CategoryList? = null
private var mTrackList: TrackList? = null
private lateinit var mPlayerManager: XmPlayerManager
override fun getContentViewLayoutID() = R.layout.activity_xmly_test
override fun isApplyKitKatTranslucency() = false
override fun initViewsAndEvents() {
tv_title.text = "喜马拉雅测试"
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
mPlayerManager = XmPlayerManager.getInstance(this)
mPlayerManager.init()
mPlayerManager.addPlayerStatusListener(mPlayerStatusListener)
// mPlayerManager.addAdsStatusListener(mAdsListener)
mPlayerManager.addOnConnectedListerner(object : XmPlayerManager.IConnectListener {
override fun onConnected() {
mPlayerManager.removeOnConnectedListerner(this)
mPlayerManager.setPlayMode(XmPlayListControl.PlayMode.PLAY_MODEL_LIST_LOOP)
Toast.makeText(this@XmlyActivity, "播放器初始化成功", Toast.LENGTH_SHORT).show()
}
})
initListener()
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.iv_left_icon -> finish()
R.id.btn1 -> {
val vo = hashMapOf<String, String>()
CommonRequest.getCategories(vo, object : IDataCallBack<CategoryList> {
override fun onSuccess(p0: CategoryList?) {
mCategoryList = p0
}
override fun onError(p0: Int, p1: String?) {
LogUtil.e(p1)
}
})
}
R.id.btn2 -> {
val vo = hashMapOf<String, String>()
vo[DTransferConstants.CATEGORY_ID] = "12"
vo[DTransferConstants.CALC_DIMENSION] = "1"
vo[DTransferConstants.PAGE] = "1"
vo["count"] = "10"
CommonRequest.getAlbumList(vo, object : IDataCallBack<AlbumList> {
override fun onSuccess(p0: AlbumList?) {
val toJson = GsonUtils.toJson(p0)
LogUtil.d(toJson)
}
override fun onError(p0: Int, p1: String?) {
LogUtil.e(p1)
}
})
}
R.id.btn3 -> {
val vo = hashMapOf<String, String>()
vo[DTransferConstants.ALBUM_ID] = "3475911"
vo[DTransferConstants.SORT] = "asc"
vo[DTransferConstants.PAGE] = "1"
vo["count"] = "10"
CommonRequest.getTracks(vo, object : IDataCallBack<TrackList> {
override fun onSuccess(p0: TrackList?) {
val toJson = GsonUtils.toJson(p0)
mTrackList = p0
LogUtil.d(toJson)
}
override fun onError(p0: Int, p1: String?) {
LogUtil.e(p1)
}
})
}
R.id.btn4 -> {
mTrackList?.let {
mPlayerManager.playList(it.tracks, 0)
}
}
}
}
private val mPlayerStatusListener: IXmPlayerStatusListener = object : IXmPlayerStatusListener {
override fun onSoundPrepared() {
Log.i(TAG, "onSoundPrepared")
// mSeekBar.setEnabled(true)
// mProgress.setVisibility(View.GONE)
}
override fun onSoundSwitch(laModel: PlayableModel?, curModel: PlayableModel?) {
Log.i(TAG, "onSoundSwitch index:$curModel")
// val model = mPlayerManager.currSound
// if (model != null) {
// var title: String? = null
// var coverUrl: String? = null
// if (model is Track) {
// val info = model
// title = info.trackTitle
// coverUrl = info.coverUrlLarge
// } else if (model is Schedule) {
// val program = model
// title = program.relatedProgram.programName
// coverUrl = program.relatedProgram.backPicUrl
// } else if (model is Radio) {
// val radio = model
// title = radio.radioName
// coverUrl = radio.coverUrlLarge
// }
// mTextView.setText(title)
// x.image().bind(mSoundCover, coverUrl)
// }
// updateButtonStatus()
}
private fun updateButtonStatus() {
// if (mPlayerManager.hasPreSound()) {
// mBtnPreSound.setEnabled(true)
// } else {
// mBtnPreSound.setEnabled(false)
// }
// if (mPlayerManager.hasNextSound()) {
// mBtnNextSound.setEnabled(true)
// } else {
// mBtnNextSound.setEnabled(false)
// }
}
override fun onPlayStop() {
Log.i(TAG, "onPlayStop")
// mBtnPlay.setImageResource(R.drawable.widget_play_normal)
}
override fun onPlayStart() {
Log.i(TAG, "onPlayStart")
// mBtnPlay.setImageResource(R.drawable.widget_pause_normal)
}
override fun onPlayProgress(currPos: Int, duration: Int) {
var title: String? = ""
val info = mPlayerManager.currSound
if (info != null) {
if (info is Track) {
title = info.trackTitle
} else if (info is Schedule) {
title = info.relatedProgram.programName
} else if (info is Radio) {
title = info.radioName
}
}
// mTextView.setText(title)
// mTime.setText("[" + ToolUtil.formatTime(currPos).toString() + "/" + ToolUtil.formatTime(duration).toString() + "]")
// if (mUpdateProgress && duration != 0) {
// mSeekBar.setProgress((100 * currPos / duration.toFloat()).toInt())
// }
// if (info is Track) {
// println("MainFragmentActivity.onPlayProgress " + currPos + " " + duration + " " + info.duration)
// }
}
override fun onPlayPause() {
Log.i(TAG, "onPlayPause")
// mBtnPlay.setImageResource(R.drawable.widget_play_normal)
}
override fun onSoundPlayComplete() {
Log.i(TAG, "onSoundPlayComplete")
// Toast.makeText(this@MainFragmentActivity, "播放完成", Toast.LENGTH_SHORT).show()
// mBtnPlay.setImageResource(R.drawable.widget_play_normal)
}
override fun onError(exception: XmPlayerException): Boolean {
Log.i(TAG, "XmPlayerException = onError " + exception.message + " " + XmPlayerManager.getInstance(this@XmlyActivity).isPlaying)
// println("MainFragmentActivity.onError $exception")
// mBtnPlay.setImageResource(R.drawable.widget_play_normal)
// if (!NetworkType.isConnectTONetWork(mContext)) {
// Toast.makeText(this@MainFragmentActivity, "没有网络导致停止播放", Toast.LENGTH_SHORT).show()
// }
return false
}
override fun onBufferProgress(position: Int) {
// mSeekBar.setSecondaryProgress(position)
// println("MainFragmentActivity.onBufferProgress $position")
}
override fun onBufferingStart() {
Log.i(TAG, "onBufferingStart " + XmPlayerManager.getInstance(this@XmlyActivity).isPlaying)
// mSeekBar.setEnabled(false)
// mProgress.setVisibility(View.VISIBLE)
}
override fun onBufferingStop() {
Log.i(TAG, "onBufferingStop")
// mSeekBar.setEnabled(true)
// mProgress.setVisibility(View.GONE)
}
}
override fun onDestroy() {
if (mPlayerManager != null) {
mPlayerManager.removePlayerStatusListener(mPlayerStatusListener)
}
XmPlayerManager.release()
CommonRequest.release()
super.onDestroy()
}
private fun initListener() {
iv_left_icon.setOnClickListener(this)
btn1.setOnClickListener(this)
btn2.setOnClickListener(this)
btn3.setOnClickListener(this)
btn4.setOnClickListener(this)
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/header_layout" />
<com.mints.goodmoney.ui.widgets.ElasticScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="获取分类数据" />
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="获取专辑数据" />
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="获取专辑内容" />
<Button
android:id="@+id/btn4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="播放专辑内容" />
</LinearLayout>
</com.mints.goodmoney.ui.widgets.ElasticScrollView>
</LinearLayout>
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