├── LICENSE ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── ic_launcher-playstore.png │ ├── java │ └── com │ │ └── raspberry │ │ ├── MainActivity.java │ │ ├── PlayerActivity.java │ │ ├── VideoService.java │ │ ├── VideoServiceEvent.java │ │ └── upnp │ │ ├── MediaRenderer │ │ ├── MediaRendererNoMedia.java │ │ ├── MediaRendererPausedPlay.java │ │ ├── MediaRendererPlaying.java │ │ ├── MediaRendererStateMachine.java │ │ └── MediaRendererStopped.java │ │ └── UpnpService.java │ └── res │ ├── drawable │ ├── ic_launcher_background.xml │ └── video_loading.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_player.xml │ └── activity_player_bottom.xml │ ├── mipmap-anydpi-v26 │ ├── ic_banner.xml │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_banner.png │ ├── ic_banner_foreground.png │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── values-zh-rCN │ └── strings.xml │ ├── values-zh-rHK │ └── strings.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── player-java ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── raspberry │ │ └── player │ │ ├── listener │ │ └── VideoListener.java │ │ └── player │ │ └── VideoPlayer.java │ └── res │ └── values │ └── strings.xml ├── raspberry.png └── settings.gradle /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 游游 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry 2 | Android TV 投屏 3 | 4 | ## 简介 5 | 6 | 咕咕咕,咕咕咕咕咕? 7 | 8 | ## 特性 9 | 10 | - 遥控器导航上下键对应进度条显示/隐藏 11 | - 遥控器导航左右键对应后退/快进 12 | - 部分视频无法后退或快进,但可以暂停(例如*央视频*) 13 | 14 | ## 未来计划 15 | 16 | - [ ] 手动设置是否开启opensles、硬解 17 | - [ ] strings.xml 18 | - [ ] 控制端接口处理 19 | - [ ] 手机控制暂停播放 20 | - [ ] 支持调用其他播放器 21 | - bugs: 22 | - [ ] 有的视频莫名其妙快进几秒(Logcat会显示已有DNS缓存但找不到路由) 23 | - [ ] 开始播放的前几秒掉帧并无声音(原因:opensles) 24 | 25 | ## 版本 / 架构 26 | 27 | - API 21+ 28 | - `armeabi-v7a` `arm64-v8a` `x86` `x86_64` 29 | 30 | ## 开源许可 / 来源信息 31 | 32 | | Repositories | License | 33 | | -------------------------------------------------- | ------------------------------------------------------------ | 34 | | [ijkplayer](https://github.com/bilibili/ijkplayer) | [GPLv2](https://github.com/bilibili/ijkplayer/blob/master/COPYING.GPLv2) | 35 | | [Cling](https://github.com/4thline/cling) | [LGPL](http://www.gnu.org/licenses/lgpl-2.1.html) | 36 | 37 | > Icon made by [Freepik](https://www.flaticon.com/authors/freepik) from [www.flaticon.com](http://www.flaticon.com/) 38 | 39 | > - [kgplayer](https://github.com/JustForYouT/kgplayer) 40 | > - [Myijkplayer](https://github.com/979451341/Myijkplayer) 41 | > - [View显示隐藏渐变动画](https://www.jianshu.com/p/d4b54d65fb89) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 31 5 | buildToolsVersion "30.0.3" 6 | defaultConfig { 7 | applicationId 'com.raspberry' 8 | minSdkVersion 21 9 | targetSdkVersion 31 10 | versionCode 20220106 11 | versionName "0.1.3" 12 | } 13 | buildTypes { 14 | release { 15 | buildConfigField "boolean", "LOG_DEBUG", "false" 16 | minifyEnabled true 17 | zipAlignEnabled true 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | shrinkResources true 20 | multiDexEnabled true 21 | } 22 | } 23 | packagingOptions { 24 | exclude 'META-INF/*' 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation project(':player-java') 31 | 32 | implementation "androidx.annotation:annotation:1.1.0" 33 | implementation "androidx.legacy:legacy-support-v4:1.0.0" 34 | implementation "androidx.appcompat:appcompat:1.2.0" 35 | 36 | implementation 'org.fourthline.cling:cling-core:2.1.1' 37 | implementation 'org.fourthline.cling:cling-support:2.1.1' 38 | 39 | implementation 'org.eclipse.jetty:jetty-servlet:8.1.12.v20130726' 40 | implementation 'org.eclipse.jetty:jetty-client:8.1.12.v20130726' 41 | implementation 'org.eclipse.jetty:jetty-server:8.1.12.v20130726' 42 | 43 | 44 | testImplementation 'junit:junit:4.13' 45 | } 46 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\eclipse\android-sdk-windows/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 19 | 20 | 21 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.raspberry; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.ServiceConnection; 7 | import android.os.*; 8 | 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import android.util.Log; 12 | import android.view.KeyEvent; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import com.raspberry.upnp.MediaRenderer.MediaRendererNoMedia; 17 | import com.raspberry.upnp.MediaRenderer.MediaRendererStateMachine; 18 | import com.raspberry.upnp.UpnpService; 19 | 20 | 21 | import org.fourthline.cling.android.AndroidUpnpService; 22 | import org.fourthline.cling.binding.LocalServiceBindingException; 23 | import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder; 24 | import org.fourthline.cling.controlpoint.ActionCallback; 25 | import org.fourthline.cling.model.ValidationException; 26 | import org.fourthline.cling.model.action.ActionInvocation; 27 | import org.fourthline.cling.model.message.UpnpResponse; 28 | import org.fourthline.cling.model.meta.DeviceDetails; 29 | import org.fourthline.cling.model.meta.DeviceIdentity; 30 | import org.fourthline.cling.model.meta.LocalDevice; 31 | import org.fourthline.cling.model.meta.LocalService; 32 | import org.fourthline.cling.model.meta.ManufacturerDetails; 33 | import org.fourthline.cling.model.meta.ModelDetails; 34 | import org.fourthline.cling.model.types.DeviceType; 35 | import org.fourthline.cling.model.types.UDADeviceType; 36 | import org.fourthline.cling.model.types.UDN; 37 | import org.fourthline.cling.support.avtransport.callback.Play; 38 | import org.fourthline.cling.support.avtransport.callback.SetAVTransportURI; 39 | import org.fourthline.cling.support.avtransport.impl.AVTransportService; 40 | import org.fourthline.cling.support.avtransport.lastchange.AVTransportLastChangeParser; 41 | import org.fourthline.cling.support.lastchange.LastChangeAwareServiceManager; 42 | import org.fourthline.cling.support.lastchange.LastChangeParser; 43 | 44 | import java.net.URI; 45 | 46 | 47 | public class MainActivity extends AppCompatActivity { 48 | private AndroidUpnpService upnpService; 49 | 50 | private final String TAG = "MainActivity"; 51 | private VideoService videoService; 52 | 53 | private final String device = Build.MODEL; 54 | private final String brand = Build.BRAND; 55 | 56 | 57 | private LocalService service; 58 | 59 | @Override 60 | protected void onCreate(Bundle savedInstanceState) { 61 | super.onCreate(savedInstanceState); 62 | setContentView(R.layout.activity_main); 63 | TextView textView = findViewById(R.id.friendlyName); 64 | bindService(); 65 | 66 | textView.setText(device + " - " + getString(R.string.app_name)); 67 | Log.i(TAG, "device: " + device); 68 | Log.i(TAG, "brand: " + brand); 69 | 70 | final Handler handler = new Handler(Looper.getMainLooper()); 71 | Runnable runnable = new Runnable() { 72 | @Override 73 | public void run() { 74 | //要做的事情 75 | LastChangeAwareServiceManager manager = (LastChangeAwareServiceManager) service.getManager(); 76 | manager.fireLastChange(); 77 | 78 | handler.postDelayed(this, 1000); 79 | } 80 | }; 81 | handler.postDelayed(runnable, 1000); 82 | } 83 | 84 | private void bindService() { 85 | // bind video service 86 | Log.d(TAG, "bindService(VideoService): " + getApplicationContext().bindService(new Intent(this, VideoService.class), new ServiceConnection() { 87 | @Override 88 | public void onServiceConnected(ComponentName name, IBinder service) { 89 | videoService = ((VideoService.VideoBinder) service).getService(); 90 | 91 | //注册回调接口 92 | videoService.bindEvent(new VideoServiceEvent() { 93 | @Override 94 | public void onDestroy() { 95 | 96 | } 97 | 98 | @Override 99 | public void onNewMedia(URI uri, String metaData) { 100 | Log.d(TAG, "onNewMedia(Event): " + uri.toString() + ", metaData: " + metaData); 101 | 102 | VideoService.destroyAll(); 103 | 104 | Intent intent = new Intent(MainActivity.this, PlayerActivity.class); 105 | intent.putExtra("uri", uri); 106 | MainActivity.this.startActivity(intent); 107 | } 108 | }); 109 | } 110 | 111 | @Override 112 | public void onServiceDisconnected(ComponentName name) { 113 | 114 | } 115 | 116 | }, BIND_AUTO_CREATE)); 117 | 118 | // bind upnp service 119 | Log.d(TAG, "bindService(UpnpService): " + getApplicationContext().bindService(new Intent(this, UpnpService.class), new ServiceConnection() { 120 | @Override 121 | public void onServiceConnected(ComponentName name, IBinder service) { 122 | upnpService = (AndroidUpnpService) service; 123 | 124 | // Register the device when this activity binds to the service for the first time 125 | try { 126 | upnpService.getRegistry().addDevice(createDevice()); 127 | 128 | 129 | Log.i(TAG, "Starting UPnP Server"); 130 | } catch (Exception err) { 131 | Log.e(TAG, "Exception: " + err); 132 | err.printStackTrace(System.err); 133 | System.exit(1); 134 | } 135 | } 136 | 137 | @Override 138 | public void onServiceDisconnected(ComponentName name) { 139 | upnpService = null; 140 | } 141 | }, BIND_AUTO_CREATE)); 142 | } 143 | 144 | private long exitTime = 0; 145 | 146 | @Override 147 | public boolean onKeyDown(int keyCode, KeyEvent event) { 148 | 149 | if (keyCode == KeyEvent.KEYCODE_BACK) { 150 | if ((System.currentTimeMillis() - exitTime) > 2000) { 151 | Toast.makeText(getApplicationContext(), R.string.app_exit, 152 | Toast.LENGTH_SHORT).show(); 153 | exitTime = System.currentTimeMillis(); 154 | } else { 155 | System.exit(0); 156 | } 157 | return true; 158 | } 159 | return super.onKeyDown(keyCode, event); 160 | } 161 | 162 | public LocalDevice createDevice() throws ValidationException, LocalServiceBindingException { 163 | // 设备标识 164 | //DeviceIdentity identity = new DeviceIdentity(UDN.uniqueSystemIdentifier("MediaRenderer")); 165 | DeviceIdentity identity = new DeviceIdentity(new UDN("MediaRenderer")); 166 | 167 | // 设备类型,包含包含版本号。此例中是,BinaryLight:1 168 | DeviceType type = new UDADeviceType("MediaRenderer", 1); 169 | 170 | DeviceDetails details = 171 | new DeviceDetails( 172 | device + " - " + getString(R.string.app_name), 173 | new ManufacturerDetails(brand), 174 | new ModelDetails( 175 | "MediaRenderer", 176 | "MediaRenderer", 177 | "v1", 178 | "https://github.com/you9you/Raspberry" 179 | ) 180 | ); 181 | 182 | service = new AnnotationLocalServiceBinder().read(AVTransportService.class); 183 | 184 | // Service's which have "logical" instances are very special, they use the 185 | // "LastChange" mechanism for eventing. This requires some extra wrappers. 186 | LastChangeParser lastChangeParser = new AVTransportLastChangeParser(); 187 | 188 | service.setManager( 189 | new LastChangeAwareServiceManager(service, lastChangeParser) { 190 | @Override 191 | protected AVTransportService createServiceInstance() throws Exception { 192 | return new AVTransportService( 193 | MediaRendererStateMachine.class, // All states 194 | MediaRendererNoMedia.class // Initial state 195 | ); 196 | } 197 | } 198 | ); 199 | 200 | // 但是,还有一个细节需要考虑:LastChange事件的传播。 201 | // 当任何播放状态或转换向LastChange添加“更改”时,这些数据将被累积。 202 | // 它不会立即或自动发送到GENA订户!如何以及何时将所有累积的更改刷新到控制点由你决定。 203 | // 一种常见的方法是后台线程每秒钟(甚至更频繁地)执行这个操作 204 | //LastChangeAwareServiceManager manager = (LastChangeAwareServiceManager)service.getManager(); 205 | //manager.fireLastChange(); 206 | 207 | /* 208 | ActionCallback setAVTransportURIAction = 209 | new SetAVTransportURI(service, "http://10.0.0.1/file.mp3", "NO METADATA") { 210 | @Override 211 | public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { 212 | // Something was wrong 213 | } 214 | }; 215 | 216 | ActionCallback playAction = 217 | new Play(service) { 218 | @Override 219 | public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { 220 | // Something was wrong 221 | } 222 | }; 223 | */ 224 | 225 | return new LocalDevice(identity, type, details, service); 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/PlayerActivity.java: -------------------------------------------------------------------------------- 1 | package com.raspberry; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Intent; 5 | import android.content.ServiceConnection; 6 | import android.os.*; 7 | import android.util.Log; 8 | import android.view.KeyEvent; 9 | import android.view.View; 10 | import android.view.animation.AlphaAnimation; 11 | import android.view.animation.Animation; 12 | import android.widget.RelativeLayout; 13 | import android.widget.SeekBar; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import androidx.appcompat.app.AppCompatActivity; 18 | 19 | import com.raspberry.player.listener.VideoListener; 20 | import com.raspberry.player.player.VideoPlayer; 21 | 22 | 23 | import java.io.IOException; 24 | import java.net.URI; 25 | 26 | import org.fourthline.cling.support.lastchange.LastChangeAwareServiceManager; 27 | import tv.danmaku.ijk.media.player.IMediaPlayer; 28 | 29 | public class PlayerActivity extends AppCompatActivity implements VideoListener { 30 | private final String TAG = "PlayerActivity"; 31 | public static final int MSG_REFRESH = 1001; 32 | private TextView tvTime; 33 | private SeekBar seekBar; 34 | 35 | private Handler handler; 36 | public VideoPlayer videoPlayer; 37 | private RelativeLayout Loading; 38 | private RelativeLayout layoutBottom; 39 | 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_player); 45 | videoPlayer = findViewById(R.id.video); 46 | Loading = findViewById(R.id.loading); 47 | tvTime = findViewById(R.id.tv_time); 48 | seekBar = findViewById(R.id.seekBar); 49 | layoutBottom = findViewById(R.id.include_player_bottom); 50 | 51 | 52 | init(); 53 | } 54 | 55 | private void init() { 56 | videoPlayer.setVideoListener(this); 57 | videoPlayer.setEnableMediaCodec(false); 58 | 59 | handler = new Handler(Looper.getMainLooper()) { 60 | @Override 61 | public void handleMessage(Message msg) { 62 | if (msg.what == MSG_REFRESH) { 63 | if (DEV == 0) { 64 | refresh(); 65 | handler.sendEmptyMessageDelayed(MSG_REFRESH, 500); 66 | } 67 | 68 | //LastChangeAwareServiceManager manager = (LastChangeAwareServiceManager) service.getManager(); 69 | //manager.fireLastChange(); 70 | } 71 | } 72 | }; 73 | 74 | Log.d(TAG, "bindService: " + getApplicationContext().bindService(new Intent(this, VideoService.class), new ServiceConnection() { 75 | @Override 76 | public void onServiceConnected(ComponentName name, IBinder service) { 77 | VideoService videoService = ((VideoService.VideoBinder) service).getService(); 78 | 79 | //注册回调接口 80 | videoService.bindOnDestroy(new VideoServiceEvent() { 81 | @Override 82 | public void onDestroy() { 83 | exit(); 84 | } 85 | 86 | @Override 87 | public void onNewMedia(URI uri, String metaData) { 88 | } 89 | }); 90 | } 91 | 92 | @Override 93 | public void onServiceDisconnected(ComponentName name) { 94 | 95 | } 96 | 97 | }, BIND_AUTO_CREATE)); 98 | 99 | 100 | Intent intent = getIntent(); 101 | URI uri = (URI) intent.getSerializableExtra("uri"); 102 | Log.i(TAG, "getURI: " + uri.toString()); 103 | 104 | fadeIn(Loading); 105 | videoPlayer.setPath(uri.toString()); 106 | try { 107 | videoPlayer.load(); 108 | } catch (IOException e) { 109 | Log.e(TAG, "videoPlayer.load: ", e); 110 | } 111 | } 112 | 113 | private void exit() { 114 | videoPlayer.stop(); 115 | videoPlayer.release(); 116 | handler.removeCallbacksAndMessages(null); 117 | finish(); 118 | } 119 | 120 | private long exitTime = 0; 121 | private final Handler mHandler = new Handler(Looper.getMainLooper()); 122 | private RunnableSeek runnableSeek; 123 | 124 | int[] DEV_array = {5, 5, 10, 20, 30, 60}; 125 | private int INC = 0; 126 | private int DEC = 0; 127 | private long time = 0; 128 | private int DEV = 0; 129 | 130 | @Override 131 | public boolean onKeyDown(int keyCode, KeyEvent event) { 132 | if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { 133 | if (videoPlayer.isPlaying()) { 134 | fadeIn(layoutBottom); 135 | videoPlayer.pause(); 136 | } else { 137 | fadeOut(layoutBottom); 138 | videoPlayer.start(); 139 | } 140 | return true; 141 | } 142 | if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { 143 | fadeIn(layoutBottom); 144 | return true; 145 | } 146 | if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { 147 | fadeOut(layoutBottom); 148 | return true; 149 | } 150 | if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { 151 | if (runnableSeek != null) { 152 | mHandler.removeCallbacks(runnableSeek); 153 | runnableSeek = null; 154 | } 155 | fadeIn(layoutBottom); 156 | 157 | runnableSeek = new RunnableSeek(); 158 | mHandler.postDelayed(runnableSeek, 500); 159 | 160 | DEV -= DEV_array[DEC]; 161 | if (DEC < DEV_array.length - 1) 162 | DEC += 1; 163 | if (INC != 0) 164 | INC -= 1; 165 | 166 | long current = videoPlayer.getCurrentPosition() / 1000 + DEV; 167 | long duration = videoPlayer.getDuration() / 1000; 168 | refresh(current, duration); 169 | 170 | return true; 171 | } 172 | if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { 173 | if (runnableSeek != null) { 174 | mHandler.removeCallbacks(runnableSeek); 175 | runnableSeek = null; 176 | } 177 | fadeIn(layoutBottom); 178 | 179 | runnableSeek = new RunnableSeek(); 180 | mHandler.postDelayed(runnableSeek, 500); 181 | 182 | DEV += DEV_array[INC]; 183 | if (INC < DEV_array.length - 1) 184 | INC += 1; 185 | if (DEC != 0) 186 | DEC -= 1; 187 | 188 | long current = videoPlayer.getCurrentPosition() / 1000 + DEV; 189 | long duration = videoPlayer.getDuration() / 1000; 190 | refresh(current, duration); 191 | 192 | return true; 193 | } 194 | if (keyCode == KeyEvent.KEYCODE_BACK) { 195 | if ((System.currentTimeMillis() - exitTime) > 2000) { 196 | Toast.makeText(getApplicationContext(), R.string.player_exit, 197 | Toast.LENGTH_SHORT).show(); 198 | exitTime = System.currentTimeMillis(); 199 | } else { 200 | exit(); 201 | } 202 | return true; 203 | } 204 | return super.onKeyDown(keyCode, event); 205 | } 206 | 207 | private void refresh() { 208 | long current = videoPlayer.getCurrentPosition() / 1000; 209 | long duration = videoPlayer.getDuration() / 1000; 210 | refresh(current, duration); 211 | } 212 | 213 | private void refresh(long current, long duration) { 214 | Log.d(TAG, "refresh: " + current + " " + duration); 215 | long current_second = current % 60; 216 | long current_minute = current / 60; 217 | long total_second = duration % 60; 218 | long total_minute = duration / 60; 219 | String time = getTime(current_minute, current_second) + "/" + getTime(total_minute, total_second); 220 | tvTime.setText(time); 221 | if (duration != 0) { 222 | seekBar.setProgress((int) (current * 100 / duration)); 223 | } 224 | } 225 | 226 | private String getTime(long minute, long second) { 227 | String min = String.valueOf(minute); 228 | String sec = String.valueOf(second); 229 | if (min.length() == 1) 230 | min = "0" + min; 231 | if (sec.length() == 1) 232 | sec = "0" + sec; 233 | 234 | return min + ":" + sec; 235 | } 236 | 237 | private class RunnableSeek implements Runnable { 238 | @Override 239 | public void run() { 240 | time = videoPlayer.getCurrentPosition() + DEV * 1000L; 241 | if (time < 0) time = 0; 242 | 243 | Log.d(TAG, "seek old-time: " + videoPlayer.getCurrentPosition()); 244 | Log.d(TAG, "seek new-value: " + DEV * 1000L); 245 | Log.d(TAG, "seek new-time: " + time); 246 | 247 | INC = 0; 248 | DEC = 0; 249 | DEV = 0; 250 | 251 | videoPlayer.seekTo(time); 252 | handler.sendEmptyMessageDelayed(MSG_REFRESH, 100); 253 | if (videoPlayer.isPlaying()) 254 | fadeOut(layoutBottom); 255 | } 256 | } 257 | 258 | @Override 259 | public void onBufferingUpdate(IMediaPlayer iMediaPlayer, int i) { 260 | 261 | } 262 | 263 | @Override 264 | public void onCompletion(IMediaPlayer iMediaPlayer) { 265 | 266 | } 267 | 268 | @Override 269 | public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) { 270 | return false; 271 | } 272 | 273 | @Override 274 | public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) { 275 | return false; 276 | } 277 | 278 | @Override 279 | public void onPrepared(IMediaPlayer iMediaPlayer) { 280 | videoPlayer.start(); 281 | fadeOut(Loading); 282 | fadeOut(layoutBottom); 283 | handler.sendEmptyMessageDelayed(MSG_REFRESH, 500); 284 | } 285 | 286 | @Override 287 | public void onSeekComplete(IMediaPlayer iMediaPlayer) { 288 | 289 | } 290 | 291 | @Override 292 | public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) { 293 | 294 | } 295 | 296 | public static void fadeIn(View view) { 297 | if (view.getVisibility() == View.VISIBLE) return; 298 | 299 | view.setVisibility(View.VISIBLE); 300 | Animation animation = new AlphaAnimation(0F, 1F); 301 | animation.setDuration(300); 302 | view.startAnimation(animation); 303 | } 304 | 305 | public static void fadeOut(View view) { 306 | if (view.getVisibility() != View.VISIBLE) return; 307 | 308 | Animation animation = new AlphaAnimation(1F, 0F); 309 | animation.setDuration(300); 310 | view.startAnimation(animation); 311 | view.setVisibility(View.GONE); 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/VideoService.java: -------------------------------------------------------------------------------- 1 | package com.raspberry; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | 6 | import android.os.Binder; 7 | import android.os.IBinder; 8 | import android.util.Log; 9 | 10 | import java.net.URI; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | 15 | public class VideoService extends Service { 16 | private final String TAG = "VideoService"; 17 | 18 | // onDestroy 19 | private static final List eventList = new ArrayList<>(); 20 | 21 | private static VideoServiceEvent event = new VideoServiceEvent() { 22 | // default 23 | @Override 24 | public void onNewMedia(URI uri, String metaData) { 25 | Log.d("VideoService", "onNewMedia(default): " + uri.toString()); 26 | } 27 | 28 | @Override 29 | public void onDestroy() { 30 | Log.d("VideoService", "onDestroy(default)"); 31 | } 32 | }; 33 | 34 | 35 | public class VideoBinder extends Binder { 36 | VideoService getService() { 37 | return VideoService.this; 38 | } 39 | } 40 | 41 | 42 | @Override 43 | public int onStartCommand(Intent intent, int flags, int startId) { 44 | Log.d(TAG, "onStartCommand"); 45 | 46 | return super.onStartCommand(intent, flags, startId); 47 | } 48 | 49 | public void bindOnDestroy(VideoServiceEvent event) { 50 | Log.d(TAG, "bindEvent"); 51 | 52 | eventList.add(event); 53 | } 54 | 55 | public static void destroyAll() { 56 | for (VideoServiceEvent event : eventList) { 57 | event.onDestroy(); 58 | } 59 | eventList.clear(); 60 | } 61 | 62 | public void bindEvent(VideoServiceEvent event) { 63 | Log.d(TAG, "bindEvent"); 64 | VideoService.event = event; 65 | } 66 | 67 | public static VideoServiceEvent getEvent() { 68 | return event; 69 | } 70 | 71 | 72 | @Override 73 | public boolean onUnbind(Intent intent) { 74 | return super.onUnbind(intent); 75 | } 76 | 77 | @Override 78 | public IBinder onBind(Intent intent) { 79 | Log.d(TAG, "onBind"); 80 | // 通过 Binder 来保持 Activity 和 Service 的通信 81 | return new VideoBinder(); 82 | } 83 | } -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/VideoServiceEvent.java: -------------------------------------------------------------------------------- 1 | package com.raspberry; 2 | 3 | import java.net.URI; 4 | 5 | public interface VideoServiceEvent { 6 | void onNewMedia(URI uri, String metaData); 7 | void onDestroy(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/MediaRenderer/MediaRendererNoMedia.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp.MediaRenderer; 2 | 3 | import com.raspberry.VideoService; 4 | 5 | import org.fourthline.cling.support.avtransport.impl.state.NoMediaPresent; 6 | import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable; 7 | import org.fourthline.cling.support.model.AVTransport; 8 | import org.fourthline.cling.support.model.MediaInfo; 9 | import org.fourthline.cling.support.model.PositionInfo; 10 | 11 | import java.net.URI; 12 | 13 | public class MediaRendererNoMedia extends NoMediaPresent { 14 | public MediaRendererNoMedia(AVTransport transport) { 15 | super(transport); 16 | } 17 | 18 | 19 | @Override 20 | public Class setTransportURI(URI uri, String metaData) { 21 | getTransport().setMediaInfo(new MediaInfo(uri.toString(), metaData)); 22 | 23 | // if you can, you should find and set the duration of the track here! 24 | getTransport().setPositionInfo(new PositionInfo(1, metaData, uri.toString())); 25 | 26 | // it's up to you what "last changes" you want to announce to event listeners 27 | getTransport().getLastChange().setEventedValue( 28 | getTransport().getInstanceId(), 29 | new AVTransportVariable.AVTransportURI(uri), 30 | new AVTransportVariable.CurrentTrackURI(uri) 31 | ); 32 | 33 | VideoService.getEvent().onNewMedia(uri, metaData); 34 | //MainActivity.newMedia(uri); 35 | 36 | return MediaRendererPlaying.class; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/MediaRenderer/MediaRendererPausedPlay.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp.MediaRenderer; 2 | 3 | import com.raspberry.VideoService; 4 | 5 | import org.fourthline.cling.support.avtransport.impl.state.PausedPlay; 6 | import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable; 7 | import org.fourthline.cling.support.model.AVTransport; 8 | import org.fourthline.cling.support.model.MediaInfo; 9 | import org.fourthline.cling.support.model.PositionInfo; 10 | 11 | import java.net.URI; 12 | 13 | public class MediaRendererPausedPlay extends PausedPlay { 14 | public MediaRendererPausedPlay(AVTransport transport) { 15 | super(transport); 16 | } 17 | 18 | @Override 19 | public Class setTransportURI(URI uri, String metaData) { 20 | getTransport().setMediaInfo(new MediaInfo(uri.toString(), metaData)); 21 | 22 | // if you can, you should find and set the duration of the track here! 23 | getTransport().setPositionInfo(new PositionInfo(1, metaData, uri.toString())); 24 | 25 | // it's up to you what "last changes" you want to announce to event listeners 26 | getTransport().getLastChange().setEventedValue( 27 | getTransport().getInstanceId(), 28 | new AVTransportVariable.AVTransportURI(uri), 29 | new AVTransportVariable.CurrentTrackURI(uri) 30 | ); 31 | 32 | VideoService.getEvent().onNewMedia(uri, metaData); 33 | //MainActivity.newMedia(uri); 34 | 35 | return MediaRendererStopped.class; 36 | } 37 | 38 | @Override 39 | public Class stop() { 40 | /// Same here, if you are stopped already and someone calls STOP, well... 41 | VideoService.destroyAll(); 42 | return MediaRendererStopped.class; 43 | } 44 | 45 | @Override 46 | public Class play(String s) { 47 | System.out.println("play"); 48 | return MediaRendererPlaying.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/MediaRenderer/MediaRendererPlaying.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp.MediaRenderer; 2 | 3 | import com.raspberry.VideoService; 4 | 5 | import org.fourthline.cling.support.avtransport.impl.state.Playing; 6 | import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable; 7 | import org.fourthline.cling.support.model.AVTransport; 8 | import org.fourthline.cling.support.model.MediaInfo; 9 | import org.fourthline.cling.support.model.PositionInfo; 10 | import org.fourthline.cling.support.model.SeekMode; 11 | 12 | import java.net.URI; 13 | 14 | public class MediaRendererPlaying extends Playing { 15 | public MediaRendererPlaying(AVTransport transport) { 16 | super(transport); 17 | } 18 | 19 | @Override 20 | public void onEntry() { 21 | super.onEntry(); 22 | // Start playing now! 23 | } 24 | 25 | @Override 26 | public Class setTransportURI(URI uri, String metaData) { 27 | getTransport().setMediaInfo(new MediaInfo(uri.toString(), metaData)); 28 | 29 | // if you can, you should find and set the duration of the track here! 30 | getTransport().setPositionInfo(new PositionInfo(1, metaData, uri.toString())); 31 | 32 | // it's up to you what "last changes" you want to announce to event listeners 33 | getTransport().getLastChange().setEventedValue( 34 | getTransport().getInstanceId(), 35 | new AVTransportVariable.AVTransportURI(uri), 36 | new AVTransportVariable.CurrentTrackURI(uri) 37 | ); 38 | 39 | VideoService.getEvent().onNewMedia(uri, metaData); 40 | //MainActivity.newMedia(uri); 41 | 42 | return MediaRendererStopped.class; 43 | } 44 | 45 | @Override 46 | public Class stop() { 47 | // Stop playing! 48 | VideoService.destroyAll(); 49 | return MediaRendererStopped.class; 50 | } 51 | 52 | @Override 53 | public Class play(String s) { 54 | return MediaRendererPlaying.class; 55 | } 56 | 57 | @Override 58 | public Class pause() { 59 | System.out.println("pause"); 60 | return MediaRendererPausedPlay.class; 61 | } 62 | 63 | @Override 64 | public Class next() { 65 | return null; 66 | } 67 | 68 | @Override 69 | public Class previous() { 70 | return null; 71 | } 72 | 73 | @Override 74 | public Class seek(SeekMode seekMode, String s) { 75 | System.out.println("seek:" + seekMode.ordinal() + "------" + s); 76 | 77 | return MediaRendererPausedPlay.class; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/MediaRenderer/MediaRendererStateMachine.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp.MediaRenderer; 2 | 3 | import org.fourthline.cling.support.avtransport.impl.AVTransportStateMachine; 4 | import org.seamless.statemachine.States; 5 | 6 | @States({ 7 | MediaRendererNoMedia.class, 8 | MediaRendererStopped.class, 9 | MediaRendererPlaying.class, 10 | MediaRendererPausedPlay.class 11 | }) 12 | public interface MediaRendererStateMachine extends AVTransportStateMachine{} 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/MediaRenderer/MediaRendererStopped.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp.MediaRenderer; 2 | 3 | import com.raspberry.VideoService; 4 | 5 | import android.util.Log; 6 | 7 | import org.fourthline.cling.support.avtransport.impl.state.Stopped; 8 | import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable; 9 | import org.fourthline.cling.support.model.AVTransport; 10 | import org.fourthline.cling.support.model.MediaInfo; 11 | import org.fourthline.cling.support.model.PositionInfo; 12 | import org.fourthline.cling.support.model.SeekMode; 13 | 14 | import java.net.URI; 15 | 16 | public class MediaRendererStopped extends Stopped { 17 | 18 | public MediaRendererStopped(AVTransport transport) { 19 | super(transport); 20 | } 21 | 22 | public void onEntry() { 23 | super.onEntry(); 24 | // Optional: Stop playing, release resources, etc. 25 | } 26 | 27 | @Override 28 | public Class setTransportURI(URI uri, String metaData) { 29 | // This operation can be triggered in any state, you should think 30 | // about how you'd want your player to react. If we are in Stopped 31 | // state nothing much will happen, except that you have to set 32 | // the media and position info, just like in MyRendererNoMediaPresent. 33 | // However, if this would be the MyRendererPlaying state, would you 34 | // prefer stopping first? 35 | getTransport().setMediaInfo(new MediaInfo(uri.toString(), metaData)); 36 | 37 | // if you can, you should find and set the duration of the track here! 38 | getTransport().setPositionInfo(new PositionInfo(1, metaData, uri.toString())); 39 | 40 | // it's up to you what "last changes" you want to announce to event listeners 41 | getTransport().getLastChange().setEventedValue( 42 | getTransport().getInstanceId(), 43 | new AVTransportVariable.AVTransportURI(uri), 44 | new AVTransportVariable.CurrentTrackURI(uri) 45 | ); 46 | 47 | VideoService.getEvent().onNewMedia(uri, metaData); 48 | //MainActivity.newMedia(uri); 49 | 50 | return MediaRendererStopped.class; 51 | } 52 | 53 | @Override 54 | public Class stop() { 55 | /// Same here, if you are stopped already and someone calls STOP, well... 56 | VideoService.destroyAll(); 57 | return MediaRendererStopped.class; 58 | } 59 | 60 | @Override 61 | public Class play(String speed) { 62 | // It's easier to let this classes' onEntry() method do the work 63 | System.out.println("speed:" + speed); 64 | return MediaRendererPlaying.class; 65 | } 66 | 67 | @Override 68 | public Class next() { 69 | return MediaRendererStopped.class; 70 | } 71 | 72 | @Override 73 | public Class previous() { 74 | return MediaRendererStopped.class; 75 | } 76 | 77 | @Override 78 | public Class seek(SeekMode unit, String target) { 79 | // Implement seeking with the stream in stopped state! 80 | Log.d("cling", "seek: " + target); 81 | return MediaRendererStopped.class; 82 | } 83 | } -------------------------------------------------------------------------------- /app/src/main/java/com/raspberry/upnp/UpnpService.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.upnp; 2 | 3 | import android.util.Log; 4 | import org.fourthline.cling.android.AndroidUpnpServiceConfiguration; 5 | import org.fourthline.cling.android.AndroidUpnpServiceImpl; 6 | 7 | import org.fourthline.cling.model.types.ServiceType; 8 | import org.fourthline.cling.model.types.UDAServiceType; 9 | 10 | 11 | /** 12 | * Android Upnp服务 13 | * 描述提供的服务 14 | */ 15 | public class UpnpService extends AndroidUpnpServiceImpl { 16 | 17 | @Override 18 | protected AndroidUpnpServiceConfiguration createConfiguration() { 19 | return new AndroidUpnpServiceConfiguration() { 20 | 21 | @Override 22 | public int getRegistryMaintenanceIntervalMillis() { 23 | return 7000; 24 | } 25 | 26 | @Override 27 | public ServiceType[] getExclusiveServiceTypes() { 28 | // only care the these service below 29 | return new ServiceType[]{ 30 | new UDAServiceType("AVTransport"), 31 | new UDAServiceType("RenderingControl"), 32 | new UDAServiceType("ContentDirectory"), 33 | }; 34 | } 35 | 36 | }; 37 | } 38 | 39 | @Override 40 | public void onDestroy() { 41 | Log.d("UpnpService", "onDestroy"); 42 | super.onDestroy(); 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/video_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 14 | 15 | 16 | 17 | 27 | 28 | 34 | 35 | 41 | 42 | 52 | 53 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_player_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xhdpi/ic_banner.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_banner_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xhdpi/ic_banner_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Raspberry 4 | 5 | 再按一次退出程序 6 | 再按一次停止 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rHK/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Raspberry 4 | 再按一次退出程式 5 | 再按一次停止 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #3DDA83 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Raspberry 3 | 4 | Press again to exit the program 5 | Press again to stop 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.0.0' 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | maven { 19 | url 'http://4thline.org/m2' 20 | } 21 | } 22 | } 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | android.useAndroidX=true 19 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 19 16:05:10 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Window s 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /player-java/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 30 5 | buildToolsVersion '30.0.3' 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 30 10 | } 11 | } 12 | 13 | dependencies { 14 | implementation 'androidx.appcompat:appcompat:1.2.0' 15 | api "tv.danmaku.ijk.media:ijkplayer-java:0.8.8" 16 | 17 | api 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8' 18 | api 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8' 19 | 20 | api 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8' 21 | api 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8' 22 | 23 | } 24 | -------------------------------------------------------------------------------- /player-java/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /player-java/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /player-java/src/main/java/com/raspberry/player/listener/VideoListener.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.player.listener; 2 | 3 | import tv.danmaku.ijk.media.player.IMediaPlayer; 4 | 5 | /** 6 | * Author: wangkai(wangkai@tv365.net) 7 | * Date: 2018-10-08 8 | * Time: 17:56 9 | * Description: 10 | */ 11 | public interface VideoListener extends IMediaPlayer.OnBufferingUpdateListener, IMediaPlayer.OnCompletionListener, IMediaPlayer.OnPreparedListener, IMediaPlayer.OnInfoListener, IMediaPlayer.OnVideoSizeChangedListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnSeekCompleteListener{ 12 | } 13 | -------------------------------------------------------------------------------- /player-java/src/main/java/com/raspberry/player/player/VideoPlayer.java: -------------------------------------------------------------------------------- 1 | package com.raspberry.player.player; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.media.AudioManager; 6 | import android.net.Uri; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | 11 | import android.util.AttributeSet; 12 | import android.view.Gravity; 13 | import android.view.SurfaceHolder; 14 | import android.view.SurfaceView; 15 | import android.widget.FrameLayout; 16 | 17 | import com.raspberry.player.listener.VideoListener; 18 | 19 | import java.io.IOException; 20 | import java.util.Map; 21 | 22 | import tv.danmaku.ijk.media.player.IMediaPlayer; 23 | import tv.danmaku.ijk.media.player.IjkMediaPlayer; 24 | 25 | /** 26 | * Author: wangkai(wangkai@tv365.net) 27 | * Date: 2018-10-08 28 | * Time: 15:01 29 | * Description: 30 | */ 31 | public class VideoPlayer extends FrameLayout { 32 | 33 | /** 34 | * 由ijkplayer提供,用于播放视频,需要给他传入一个surfaceView 35 | */ 36 | private IMediaPlayer mMediaPlayer = null; 37 | /** 38 | * 视频文件地址 39 | */ 40 | private String mPath; 41 | /** 42 | * 视频请求header 43 | */ 44 | private Map mHeader; 45 | 46 | private SurfaceView mSurfaceView; 47 | 48 | private Context mContext; 49 | private boolean mEnableMediaCodec; 50 | 51 | private VideoListener mListener; 52 | private AudioManager mAudioManager; 53 | private AudioFocusHelper mAudioFocusHelper; 54 | 55 | public VideoPlayer(@NonNull Context context) { 56 | this(context, null); 57 | } 58 | 59 | public VideoPlayer(@NonNull Context context, @Nullable AttributeSet attrs) { 60 | this(context, attrs, 0); 61 | } 62 | 63 | public VideoPlayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 64 | super(context, attrs, defStyleAttr); 65 | init(context); 66 | } 67 | 68 | //初始化 69 | private void init(Context context) { 70 | mContext = context; 71 | setBackgroundColor(Color.BLACK); 72 | createSurfaceView(); 73 | mAudioManager = (AudioManager) mContext.getApplicationContext().getSystemService(Context.AUDIO_SERVICE); 74 | mAudioFocusHelper = new AudioFocusHelper(); 75 | } 76 | 77 | //创建surfaceView 78 | private void createSurfaceView() { 79 | mSurfaceView = new SurfaceView(mContext); 80 | mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { 81 | @Override 82 | public void surfaceCreated(SurfaceHolder surfaceHolder) { 83 | 84 | } 85 | 86 | @Override 87 | public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { 88 | if (mMediaPlayer != null) { 89 | mMediaPlayer.setDisplay(surfaceHolder); 90 | } 91 | } 92 | 93 | @Override 94 | public void surfaceDestroyed(SurfaceHolder surfaceHolder) { 95 | 96 | } 97 | }); 98 | LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT 99 | , LayoutParams.MATCH_PARENT, Gravity.CENTER); 100 | // mSurfaceView.setLayoutParams(layoutParams); 101 | addView(mSurfaceView, 0, layoutParams); 102 | } 103 | 104 | //创建一个新的player 105 | private IMediaPlayer createPlayer() { 106 | IjkMediaPlayer ijkMediaPlayer = new IjkMediaPlayer(); 107 | //(开启的话, 前几秒掉帧并无声音) 108 | // ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0); 109 | 110 | // ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32); 111 | 112 | 113 | // 跳帧处理 114 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1); 115 | 116 | // 最低帧 117 | // ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "min-frames", 65); 118 | 119 | // 预缓冲?? 120 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0); 121 | 122 | 123 | ijkMediaPlayer.setVolume(1.0f, 1.0f); 124 | 125 | setEnableMediaCodec(ijkMediaPlayer, mEnableMediaCodec); 126 | return ijkMediaPlayer; 127 | } 128 | 129 | //设置是否开启硬解码 130 | private void setEnableMediaCodec(IjkMediaPlayer ijkMediaPlayer, boolean isEnable) { 131 | int value = isEnable ? 1 : 0; 132 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", value); 133 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", value); 134 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", value); 135 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", value); 136 | } 137 | 138 | public void setEnableMediaCodec(boolean isEnable) { 139 | mEnableMediaCodec = isEnable; 140 | } 141 | 142 | //设置ijkplayer的监听 143 | private void setListener(IMediaPlayer player) { 144 | player.setOnPreparedListener(mPreparedListener); 145 | player.setOnVideoSizeChangedListener(mVideoSizeChangedListener); 146 | } 147 | 148 | /** 149 | * 设置自己的player回调 150 | */ 151 | public void setVideoListener(VideoListener listener) { 152 | mListener = listener; 153 | } 154 | 155 | //设置播放地址 156 | public void setPath(String path) { 157 | setPath(path, null); 158 | } 159 | 160 | public void setPath(String path, Map header) { 161 | mPath = path; 162 | mHeader = header; 163 | } 164 | 165 | //开始加载视频 166 | public void load() throws IOException { 167 | if (mMediaPlayer != null) { 168 | mMediaPlayer.stop(); 169 | mMediaPlayer.release(); 170 | } 171 | mMediaPlayer = createPlayer(); 172 | setListener(mMediaPlayer); 173 | mMediaPlayer.setDisplay(mSurfaceView.getHolder()); 174 | mMediaPlayer.setDataSource(mContext, Uri.parse(mPath), mHeader); 175 | 176 | mMediaPlayer.prepareAsync(); 177 | } 178 | 179 | public void start() { 180 | if (mMediaPlayer != null) { 181 | mMediaPlayer.start(); 182 | mAudioFocusHelper.requestFocus(); 183 | } 184 | } 185 | 186 | public void release() { 187 | if (mMediaPlayer != null) { 188 | mMediaPlayer.reset(); 189 | mMediaPlayer.release(); 190 | mMediaPlayer = null; 191 | mAudioFocusHelper.abandonFocus(); 192 | } 193 | } 194 | 195 | public void pause() { 196 | if (mMediaPlayer != null) { 197 | mMediaPlayer.pause(); 198 | mAudioFocusHelper.abandonFocus(); 199 | } 200 | } 201 | 202 | public void stop() { 203 | if (mMediaPlayer != null) { 204 | mMediaPlayer.stop(); 205 | mAudioFocusHelper.abandonFocus(); 206 | } 207 | } 208 | 209 | 210 | public void reset() { 211 | if (mMediaPlayer != null) { 212 | mMediaPlayer.reset(); 213 | mAudioFocusHelper.abandonFocus(); 214 | } 215 | } 216 | 217 | 218 | public long getDuration() { 219 | if (mMediaPlayer != null) { 220 | return mMediaPlayer.getDuration(); 221 | } else { 222 | return 0; 223 | } 224 | } 225 | 226 | 227 | public long getCurrentPosition() { 228 | if (mMediaPlayer != null) { 229 | return mMediaPlayer.getCurrentPosition(); 230 | } else { 231 | return 0; 232 | } 233 | } 234 | 235 | 236 | public void seekTo(long l) { 237 | if (mMediaPlayer != null) { 238 | mMediaPlayer.seekTo(l); 239 | } 240 | } 241 | 242 | public boolean isPlaying() { 243 | if (mMediaPlayer != null) { 244 | return mMediaPlayer.isPlaying(); 245 | } 246 | return false; 247 | } 248 | 249 | //------------------ 各种listener 赋值 ---------------------// 250 | 251 | private IMediaPlayer.OnPreparedListener mPreparedListener = new IMediaPlayer.OnPreparedListener() { 252 | 253 | @Override 254 | public void onPrepared(IMediaPlayer iMediaPlayer) { 255 | if (mListener != null) { 256 | mListener.onPrepared(iMediaPlayer); 257 | } 258 | } 259 | }; 260 | 261 | private IMediaPlayer.OnVideoSizeChangedListener mVideoSizeChangedListener = new IMediaPlayer.OnVideoSizeChangedListener() { 262 | @Override 263 | public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) { 264 | int videoWidth = iMediaPlayer.getVideoWidth(); 265 | int videoHeight = iMediaPlayer.getVideoHeight(); 266 | if (videoWidth != 0 && videoHeight != 0) { 267 | mSurfaceView.getHolder().setFixedSize(videoWidth, videoHeight); 268 | } 269 | } 270 | }; 271 | 272 | //------------------ 音频监听 ---------------------// 273 | 274 | /** 275 | * 音频焦点改变监听 276 | */ 277 | private class AudioFocusHelper implements AudioManager.OnAudioFocusChangeListener { 278 | boolean startRequested = false; 279 | boolean pausedForLoss = false; 280 | int currentFocus = 0; 281 | 282 | @Override 283 | public void onAudioFocusChange(int focusChange) { 284 | if (currentFocus == focusChange) { 285 | return; 286 | } 287 | 288 | currentFocus = focusChange; 289 | switch (focusChange) { 290 | case AudioManager.AUDIOFOCUS_GAIN://获得焦点 291 | case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT://暂时获得焦点 292 | if (startRequested || pausedForLoss) { 293 | start(); 294 | startRequested = false; 295 | pausedForLoss = false; 296 | } 297 | if (mMediaPlayer != null)//恢复音量 298 | mMediaPlayer.setVolume(1.0f, 1.0f); 299 | break; 300 | case AudioManager.AUDIOFOCUS_LOSS://焦点丢失 301 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT://焦点暂时丢失 302 | if (isPlaying()) { 303 | pausedForLoss = true; 304 | pause(); 305 | } 306 | break; 307 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK://此时需降低音量 308 | if (mMediaPlayer != null && isPlaying()) { 309 | mMediaPlayer.setVolume(0.1f, 0.1f); 310 | } 311 | break; 312 | } 313 | } 314 | 315 | boolean requestFocus() { 316 | if (currentFocus == AudioManager.AUDIOFOCUS_GAIN) { 317 | return true; 318 | } 319 | 320 | if (mAudioManager == null) { 321 | return false; 322 | } 323 | 324 | int status = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); 325 | if (AudioManager.AUDIOFOCUS_REQUEST_GRANTED == status) { 326 | currentFocus = AudioManager.AUDIOFOCUS_GAIN; 327 | return true; 328 | } 329 | 330 | startRequested = true; 331 | return false; 332 | } 333 | 334 | boolean abandonFocus() { 335 | 336 | if (mAudioManager == null) { 337 | return false; 338 | } 339 | 340 | startRequested = false; 341 | int status = mAudioManager.abandonAudioFocus(this); 342 | return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == status; 343 | } 344 | } 345 | 346 | } 347 | -------------------------------------------------------------------------------- /player-java/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | player-java 3 | 4 | -------------------------------------------------------------------------------- /raspberry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/you9you/Raspberry/7e87148954273747577269c7902cc3cf63552137/raspberry.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':player-java' 2 | --------------------------------------------------------------------------------