Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
james正哥儿
testforfloatingwindow
提交
858764c4
T
testforfloatingwindow
项目概览
james正哥儿
/
testforfloatingwindow
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
testforfloatingwindow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
858764c4
编写于
5月 31, 2018
作者:
董
董重
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
视频播放悬浮窗
上级
e597c158
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
13 deletion
+48
-13
app/build.gradle
app/build.gradle
+0
-2
app/src/main/java/dongzhong/testforfloatingwindow/FloatingVideoService.java
...dongzhong/testforfloatingwindow/FloatingVideoService.java
+44
-7
app/src/main/res/layout/video_display.xml
app/src/main/res/layout/video_display.xml
+4
-4
未找到文件。
app/build.gradle
浏览文件 @
858764c4
...
...
@@ -25,6 +25,4 @@ dependencies {
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation
'com.github.dongzhong:VideoPlayer:v1.2'
}
app/src/main/java/dongzhong/testforfloatingwindow/FloatingVideoService.java
浏览文件 @
858764c4
...
...
@@ -3,6 +3,9 @@ package dongzhong.testforfloatingwindow;
import
android.app.Service
;
import
android.content.Intent
;
import
android.graphics.PixelFormat
;
import
android.media.AudioManager
;
import
android.media.MediaPlayer
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.IBinder
;
import
android.provider.Settings
;
...
...
@@ -10,10 +13,13 @@ import android.support.annotation.Nullable;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.MotionEvent
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceView
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.widget.Toast
;
import
dongzhong.videoplayer.VideoPlayer
;
import
java.io.IOException
;
/**
* Created by admin on 2018/5/30.
...
...
@@ -25,6 +31,7 @@ public class FloatingVideoService extends Service {
private
WindowManager
windowManager
;
private
WindowManager
.
LayoutParams
layoutParams
;
private
MediaPlayer
mediaPlayer
;
private
View
displayView
;
@Override
...
...
@@ -45,6 +52,8 @@ public class FloatingVideoService extends Service {
layoutParams
.
height
=
450
;
layoutParams
.
x
=
300
;
layoutParams
.
y
=
300
;
mediaPlayer
=
new
MediaPlayer
();
}
@Nullable
...
...
@@ -63,12 +72,40 @@ public class FloatingVideoService extends Service {
if
(
Settings
.
canDrawOverlays
(
this
))
{
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
this
);
displayView
=
layoutInflater
.
inflate
(
R
.
layout
.
video_display
,
null
);
VideoPlayer
videoPlayer
=
displayView
.
findViewById
(
R
.
id
.
videoplayer_display
);
videoPlayer
.
preset
(
"https://raw.githubusercontent.com/dongzhong/ImageAndVideoStore/master/Bruno%20Mars%20-%20Treasure.mp4"
,
"Treasure - Bruno Mars"
,
true
);
windowManager
.
addView
(
displayView
,
layoutParams
);
displayView
.
setOnTouchListener
(
new
FloatingOnTouchListener
());
mediaPlayer
.
setAudioStreamType
(
AudioManager
.
STREAM_MUSIC
);
SurfaceView
surfaceView
=
displayView
.
findViewById
(
R
.
id
.
video_display_surfaceview
);
final
SurfaceHolder
surfaceHolder
=
surfaceView
.
getHolder
();
surfaceHolder
.
addCallback
(
new
SurfaceHolder
.
Callback
()
{
@Override
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
mediaPlayer
.
setDisplay
(
surfaceHolder
);
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
}
@Override
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
}
});
mediaPlayer
.
setOnPreparedListener
(
new
MediaPlayer
.
OnPreparedListener
()
{
@Override
public
void
onPrepared
(
MediaPlayer
mp
)
{
mediaPlayer
.
start
();
}
});
try
{
mediaPlayer
.
setDataSource
(
this
,
Uri
.
parse
(
"https://raw.githubusercontent.com/dongzhong/ImageAndVideoStore/master/Bruno%20Mars%20-%20Treasure.mp4"
));
mediaPlayer
.
prepareAsync
();
}
catch
(
IOException
e
)
{
Toast
.
makeText
(
this
,
"无法打开视频源"
,
Toast
.
LENGTH_LONG
).
show
();
}
windowManager
.
addView
(
displayView
,
layoutParams
);
}
}
...
...
@@ -97,7 +134,7 @@ public class FloatingVideoService extends Service {
default
:
break
;
}
return
fals
e
;
return
tru
e
;
}
}
}
app/src/main/res/layout/video_display.xml
浏览文件 @
858764c4
<?xml version="1.0" encoding="utf-8"?>
<
Frame
Layout
<
Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<
dongzhong.videoplayer.VideoPlayer
android:id=
"@+id/video
player_display
"
<
SurfaceView
android:id=
"@+id/video
_display_surfaceview
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</FrameLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录