yangchong 4 лет назад
Родитель
Сommit
5a0e7cd8fa

+ 5 - 0
AudioPlayer/src/main/java/com/yc/audioplayer/bean/AudioPlayData.java

@@ -7,6 +7,11 @@ public class AudioPlayData {
 
     public AudioTtsPriority mPriority = AudioTtsPriority.NORMAL_PRIORITY;
 
+    /**
+     * 是否播放tts,如果是文案则表示true,如果是资源文件则表示false
+     * true,使用TtsPlayer播放
+     * false,使用MediaPlayer播放
+     */
     public boolean mPlayTts = true;
 
     private String mTts;

+ 3 - 0
AudioPlayer/src/main/java/com/yc/audioplayer/deque/AudioTtsDeque.java

@@ -75,11 +75,14 @@ public class AudioTtsDeque {
      * @return
      */
     public AudioPlayData getTts() {
+        //先从高开始取
         AudioPlayData tts = mHighDeque.poll();
         if (tts == null) {
+            //如果高没有,则从中开始取
             tts = mMiddleDeque.poll();
         }
         if (tts == null) {
+            //否则则获取优先级最低的normal队列
             tts = mNormalDeque.poll();
         }
         VideoLogUtils.d("TTS queue get data is " + tts);

+ 1 - 0
AudioPlayer/src/main/java/com/yc/audioplayer/dispatch/AudioTaskDispatcher.java

@@ -31,6 +31,7 @@ public class AudioTaskDispatcher implements InterPlayListener {
     }
 
     private AudioTaskDispatcher() {
+
     }
 
     public static AudioTaskDispatcher getInstance() {

+ 10 - 2
AudioPlayer/src/main/java/com/yc/audioplayer/manager/AudioManager.java

@@ -20,7 +20,10 @@ public class AudioManager extends AbstractAudioWrapper {
     private PlayStateListener mPlayStateListener;
 
     public AudioManager(Context context) {
-        mTtsEngine = new AudioServiceDelegate(new DefaultTtsPlayer(context));
+        //创建tts播放器
+        DefaultTtsPlayer defaultTtsPlayer = new DefaultTtsPlayer(context);
+        //常见tts代理类对象
+        mTtsEngine = new AudioServiceDelegate(defaultTtsPlayer);
         //创建音频播放器
         mMediaPlayer = new MediaAudioPlayer();
     }
@@ -37,7 +40,12 @@ public class AudioManager extends AbstractAudioWrapper {
             mPlayStateListener.onStartPlay();
         }
         this.mCurrentData = data;
-        this.mCurrentAudio = data.mPlayTts ? mTtsEngine : mMediaPlayer;
+        //判断是否播放tts
+        if (data.mPlayTts){
+            this.mCurrentAudio = mTtsEngine;
+        } else {
+            this.mCurrentAudio = mMediaPlayer;
+        }
         this.mCurrentAudio.play(data);
     }
 

+ 13 - 0
AudioPlayer/src/main/java/com/yc/audioplayer/player/DefaultTtsPlayer.java

@@ -103,6 +103,7 @@ public class DefaultTtsPlayer extends AbstractAudioWrapper implements TextToSpee
     @Override
     public void play(AudioPlayData data) {
         synchronized (this.mTts) {
+            //如果是在说话中,则先停止
             if (this.mTts.isSpeaking()) {
                 this.mTts.stop();
             }
@@ -136,12 +137,20 @@ public class DefaultTtsPlayer extends AbstractAudioWrapper implements TextToSpee
 
         }
 
+        /**
+         * 播放完成
+         * @param utteranceId                       话语id
+         */
         @Override
         public void onDone(final String utteranceId) {
             VideoLogUtils.i("TTSPlayer OnCompleteListener onDone");
             onCompleted();
         }
 
+        /**
+         * 播放异常
+         * @param utteranceId                       话语id
+         */
         @Override
         public void onError(final String utteranceId) {
             VideoLogUtils.i("TTSPlayer OnCompleteListener onError");
@@ -150,6 +159,10 @@ public class DefaultTtsPlayer extends AbstractAudioWrapper implements TextToSpee
             onCompleted();
         }
 
+        /**
+         * 播放开始
+         * @param utteranceId                       话语id
+         */
         @Override
         public void onStart(final String utteranceId) {
 

+ 1 - 3
AudioPlayer/src/main/java/com/yc/audioplayer/player/MediaAudioPlayer.java

@@ -16,15 +16,13 @@ public class MediaAudioPlayer extends AbstractAudioWrapper {
 
     private InterPlayListener mPlayListener;
     private Context mContext;
-
     private MediaPlayer mMediaPlayer;
     private boolean mPause = false;
 
     /**
      * 完成/出错时的监听接口
      */
-    private OnCompletionListener mOnCompletionListener = new OnCompletionListener() {
-
+    private final OnCompletionListener mOnCompletionListener = new OnCompletionListener() {
         @Override
         public void onCompletion(MediaPlayer player) {
             if (mMediaPlayer != null && player != null && mMediaPlayer == player) {

+ 0 - 2
AudioPlayer/src/main/java/com/yc/audioplayer/spi/AudioServiceImpl.java

@@ -12,14 +12,12 @@ public class AudioServiceImpl implements AudioServiceProvider {
     private AudioManager mAudioManager;
     private final AudioTaskDispatcher mAudioTaskDispatcher = AudioTaskDispatcher.getInstance();
     private boolean mReady = false;
-    private Context mContext;
 
     @Override
     public void init(Context context) {
         mAudioManager = new AudioManager(context);
         mAudioManager.init(mAudioTaskDispatcher, context);
         mAudioTaskDispatcher.initialize(mAudioManager);
-        mContext = context;
         mReady = true;
     }
 

+ 1 - 0
VideoSqlLite/build.gradle

@@ -23,6 +23,7 @@ android {
 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation project.ext.AppDependencies['annotation']
+    implementation project(path: ':VideoTool')
 }
 
 

+ 7 - 7
VideoSqlLite/src/main/java/com/yc/videosqllite/disk/DiskLruCacheWrapper.java

@@ -6,7 +6,7 @@ import androidx.annotation.Nullable;
 import com.yc.videosqllite.manager.CacheConfig;
 import com.yc.videosqllite.manager.LocationManager;
 import com.yc.videosqllite.model.SafeKeyGenerator;
-import com.yc.videosqllite.utils.CacheLogUtils;
+import com.yc.videosqllite.utils.VideoLogUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -71,7 +71,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
                 result = value.getString(0);
             }
         } catch (IOException e) {
-            CacheLogUtils.d("DiskLruCacheWrapper-----Unable to get from disk cache-"+e);
+            VideoLogUtils.d("DiskLruCacheWrapper-----Unable to get from disk cache-"+e);
         } finally {
             try {
                 getDiskCache().flush();
@@ -87,7 +87,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
         String safeKey = safeKeyGenerator.getSafeKey(key);
         writeLocker.acquire(safeKey);
         try {
-            CacheLogUtils.d("DiskLruCacheWrapper-----Put: Obtained:"+ safeKey + " for for Key: " + key);
+            VideoLogUtils.d("DiskLruCacheWrapper-----Put: Obtained:"+ safeKey + " for for Key: " + key);
             try {
                 DiskLruCache diskCache = getDiskCache();
                 DiskLruCache.Value current = diskCache.get(safeKey);
@@ -105,7 +105,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
                     editor.abortUnlessCommitted();
                 }
             } catch (IOException e) {
-                CacheLogUtils.d("DiskLruCacheWrapper-----Unable to put from disk cache-"+e);
+                VideoLogUtils.d("DiskLruCacheWrapper-----Unable to put from disk cache-"+e);
             } finally {
                 try {
                     getDiskCache().flush();
@@ -125,7 +125,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
         try {
             isRemove = getDiskCache().remove(safeKey);
         } catch (IOException e) {
-            CacheLogUtils.d("DiskLruCacheWrapper-----Unable to delete from disk cache-"+e);
+            VideoLogUtils.d("DiskLruCacheWrapper-----Unable to delete from disk cache-"+e);
             isRemove = false;
         } finally {
             try {
@@ -150,7 +150,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
                 }
             }
         } catch (IOException e) {
-            CacheLogUtils.d("DiskLruCacheWrapper-----Unable to get from disk cache-"+e);
+            VideoLogUtils.d("DiskLruCacheWrapper-----Unable to get from disk cache-"+e);
         } finally {
             try {
                 getDiskCache().flush();
@@ -166,7 +166,7 @@ public class DiskLruCacheWrapper implements InterDiskCache {
         try {
             getDiskCache().delete();
         } catch (IOException e) {
-            CacheLogUtils.d("DiskLruCacheWrapper-----Unable to clear disk cache or disk cache cleared externally-"+e);
+            VideoLogUtils.d("DiskLruCacheWrapper-----Unable to clear disk cache or disk cache cleared externally-"+e);
         } finally {
             try {
                 getDiskCache().flush();

+ 4 - 4
VideoSqlLite/src/main/java/com/yc/videosqllite/disk/SqlLiteCache.java

@@ -4,7 +4,7 @@ import com.yc.videosqllite.manager.CacheConfig;
 import com.yc.videosqllite.manager.LocationManager;
 import com.yc.videosqllite.model.SafeKeyGenerator;
 import com.yc.videosqllite.model.VideoLocation;
-import com.yc.videosqllite.utils.CacheLogUtils;
+import com.yc.videosqllite.utils.VideoLogUtils;
 
 import java.io.File;
 
@@ -26,7 +26,7 @@ public class SqlLiteCache {
         CacheConfig cacheConfig = LocationManager.getInstance().getCacheConfig();
         File path = DiskFileUtils.getFilePath(cacheConfig.getContext());
         String pathString = path.getPath();
-        CacheLogUtils.d("SqlLiteCache-----pathString路径输出地址-"+pathString);
+        VideoLogUtils.d("SqlLiteCache-----pathString路径输出地址-"+pathString);
         this.safeKeyGenerator = new SafeKeyGenerator();
         interDiskCache = DiskLruCacheWrapper.get(path,safeKeyGenerator);
     }
@@ -43,7 +43,7 @@ public class SqlLiteCache {
         String safeKey = safeKeyGenerator.getSafeKey(url);
         location.setUrlMd5(safeKey);
         String json = location.toJson();
-        CacheLogUtils.d("SqlLiteCache-----put--json--"+json);
+        VideoLogUtils.d("SqlLiteCache-----put--json--"+json);
         interDiskCache.put(url,json);
     }
 
@@ -57,7 +57,7 @@ public class SqlLiteCache {
         if (data==null || data.length()==0){
             return -1;
         }
-        CacheLogUtils.d("SqlLiteCache-----get---"+data);
+        VideoLogUtils.d("SqlLiteCache-----get---"+data);
         VideoLocation location = VideoLocation.toObject(data);
         return location.getPosition();
     }

+ 9 - 9
VideoSqlLite/src/main/java/com/yc/videosqllite/manager/LocationManager.java

@@ -7,7 +7,7 @@ import com.yc.videosqllite.cache.VideoMapCache;
 import com.yc.videosqllite.disk.DiskFileUtils;
 import com.yc.videosqllite.disk.SqlLiteCache;
 import com.yc.videosqllite.model.VideoLocation;
-import com.yc.videosqllite.utils.CacheLogUtils;
+import com.yc.videosqllite.utils.VideoLogUtils;
 
 import java.io.IOException;
 
@@ -59,10 +59,10 @@ public class LocationManager {
 
     public void init(CacheConfig cacheConfig){
         this.cacheConfig = cacheConfig;
-        CacheLogUtils.setIsLog(cacheConfig.isLog());
+        VideoLogUtils.setIsLog(cacheConfig.isLog());
         videoMapCache = new VideoMapCache();
         sqlLiteCache = new SqlLiteCache();
-        CacheLogUtils.d("LocationManager-----init初始化-");
+        VideoLogUtils.d("LocationManager-----init初始化-");
     }
 
     public CacheConfig getCacheConfig() {
@@ -109,7 +109,7 @@ public class LocationManager {
             videoMapCache.put(url,location);
         }
         long currentTimeMillis2 = System.currentTimeMillis();
-        CacheLogUtils.d("LocationManager-----put--存数据耗时-"+(currentTimeMillis2-currentTimeMillis1));
+        VideoLogUtils.d("LocationManager-----put--存数据耗时-"+(currentTimeMillis2-currentTimeMillis1));
     }
 
     /**
@@ -150,7 +150,7 @@ public class LocationManager {
             position = videoMapCache.get(url);
         }
         long currentTimeMillis2 = System.currentTimeMillis();
-        CacheLogUtils.d("LocationManager-----get--取数据耗时-"+(currentTimeMillis2-currentTimeMillis1)
+        VideoLogUtils.d("LocationManager-----get--取数据耗时-"+(currentTimeMillis2-currentTimeMillis1)
                 + "---进度-"+position);
         return position;
     }
@@ -254,10 +254,10 @@ public class LocationManager {
     public long getUseMemory(){
         long totalMemory = Runtime.getRuntime().totalMemory();
         long freeMemory = Runtime.getRuntime().freeMemory();
-        CacheLogUtils.d("LocationManager-----内存-"+totalMemory+"-----"+freeMemory);
+        VideoLogUtils.d("LocationManager-----内存-"+totalMemory+"-----"+freeMemory);
         //long maxMemory = Runtime.getRuntime().maxMemory();
         long useMemory = totalMemory - freeMemory;
-        CacheLogUtils.d("LocationManager-----获取当前应用使用的内存-"+useMemory);
+        VideoLogUtils.d("LocationManager-----获取当前应用使用的内存-"+useMemory);
         return useMemory;
     }
 
@@ -272,7 +272,7 @@ public class LocationManager {
         }
         long totalMemory = Runtime.getRuntime().totalMemory();
         long threshold = totalMemory / proportion;
-        CacheLogUtils.d("LocationManager-----设定内存的阈值-"+threshold);
+        VideoLogUtils.d("LocationManager-----设定内存的阈值-"+threshold);
         return threshold;
     }
 
@@ -282,7 +282,7 @@ public class LocationManager {
      */
     public void dumpHprofData(Context context){
         String dump = DiskFileUtils.getPath(context, "dump");
-        CacheLogUtils.d("LocationManager-----获取Java内存快照文件-"+dump);
+        VideoLogUtils.d("LocationManager-----获取Java内存快照文件-"+dump);
         try {
             Debug.dumpHprofData(dump);
         } catch (IOException e) {

+ 5 - 5
VideoSqlLite/src/main/java/com/yc/videosqllite/model/SafeKeyGenerator.java

@@ -3,8 +3,8 @@ package com.yc.videosqllite.model;
 import com.yc.videosqllite.cache.VideoLruCache;
 import com.yc.videosqllite.manager.CacheConfig;
 import com.yc.videosqllite.manager.LocationManager;
-import com.yc.videosqllite.utils.CacheLogUtils;
-import com.yc.videosqllite.utils.VideoMd5Utils;
+import com.yc.videosqllite.utils.VideoLogUtils;
+import com.yc.videotool.VideoMd5Utils;
 
 /**
  * <pre>
@@ -32,16 +32,16 @@ public class SafeKeyGenerator {
         int hashCode = url.hashCode();
         synchronized (loadIdToSafeHash) {
             safeKey = loadIdToSafeHash.get(hashCode);
-            CacheLogUtils.d("SafeKeyGenerator-----获取缓存key-"+safeKey);
+            VideoLogUtils.d("SafeKeyGenerator-----获取缓存key-"+safeKey);
         }
         if (safeKey == null || safeKey.length()==0) {
             CacheConfig cacheConfig = LocationManager.getInstance().getCacheConfig();
             safeKey = VideoMd5Utils.encryptMD5ToString(url, cacheConfig.getSalt());
-            CacheLogUtils.d("SafeKeyGenerator-----md5转化key-"+safeKey);
+            VideoLogUtils.d("SafeKeyGenerator-----md5转化key-"+safeKey);
         }
         synchronized (loadIdToSafeHash) {
             loadIdToSafeHash.put(hashCode, safeKey);
-            CacheLogUtils.d("SafeKeyGenerator-----存储key-"+safeKey);
+            VideoLogUtils.d("SafeKeyGenerator-----存储key-"+safeKey);
         }
         return safeKey;
     }

+ 0 - 71
VideoSqlLite/src/main/java/com/yc/videosqllite/utils/CacheLogUtils.java

@@ -1,71 +0,0 @@
-/*
-Copyright 2017 yangchong211(github.com/yangchong211)
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package com.yc.videosqllite.utils;
-
-import android.util.Log;
-
-/**
- * <pre>
- *     @author yangchong
- *     blog  : https://github.com/yangchong211
- *     time  : 2017/10/21
- *     desc  : log工具
- *     revise:
- * </pre>
- */
-public final class CacheLogUtils {
-
-    private static final String TAG = "CacheLogUtils";
-    private static boolean isLog = false;
-
-    /**
-     * 设置是否开启日志
-     * @param isLog                 是否开启日志
-     */
-    public static void setIsLog(boolean isLog) {
-        com.yc.videosqllite.utils.CacheLogUtils.isLog = isLog;
-    }
-
-    public static boolean isIsLog() {
-        return isLog;
-    }
-
-    public static void d(String message) {
-        if(isLog){
-            Log.d(TAG, message);
-        }
-    }
-
-    public static void i(String message) {
-        if(isLog){
-            Log.i(TAG, message);
-        }
-
-    }
-
-    public static void e(String msg) {
-        if (isLog) {
-            Log.e(TAG, msg);
-        }
-    }
-
-    public static void e(String message, Throwable throwable) {
-        if(isLog){
-            Log.e(TAG, message, throwable);
-        }
-    }
-
-}

+ 1 - 1
VideoSqlLite/src/main/java/com/yc/videosqllite/utils/VideoMd5Utils.java → VideoTool/src/main/java/com/yc/videotool/VideoMd5Utils.java

@@ -1,4 +1,4 @@
-package com.yc.videosqllite.utils;
+package com.yc.videotool;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;