Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
ImageVideoBanner
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
ImageVideoBanner
Commits
61e53d36
Commit
61e53d36
authored
Mar 06, 2021
by
委座-江
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
高度自适应
parent
a59db2b6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
419 additions
and
89 deletions
+419
-89
AndroidManifest.xml
imageVideoBanner/src/main/AndroidManifest.xml
+12
-12
MainActivity.java
...c/main/java/com/widget/imagevideobanner/MainActivity.java
+8
-42
ImageVideoBanner.java
.../com/widget/imagevideobanner/banner/ImageVideoBanner.java
+15
-0
ImageVideoFragment.java
...om/widget/imagevideobanner/banner/ImageVideoFragment.java
+141
-30
BannerBean.java
...ain/java/com/widget/imagevideobanner/bean/BannerBean.java
+27
-0
BitmapUtils.java
...n/java/com/widget/imagevideobanner/utils/BitmapUtils.java
+201
-0
item_video_view.xml
imageVideoBanner/src/main/res/layout/item_video_view.xml
+15
-5
No files found.
imageVideoBanner/src/main/AndroidManifest.xml
View file @
61e53d36
...
@@ -15,18 +15,18 @@
...
@@ -15,18 +15,18 @@
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
android:theme=
"@style/AppTheme"
>
<
!--<activity-->
<
activity
<!--android:name=".MainActivity"-->
android:name=
".MainActivity"
<!--android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"-->
android:configChanges=
"orientation|keyboardHidden|screenSize|keyboard|navigation"
<!--android:exported="true"-->
android:exported=
"true"
<!--android:launchMode="singleTask"-->
android:launchMode=
"singleTask"
<!--android:screenOrientation="portrait">--
>
android:screenOrientation=
"portrait"
>
<
!--<intent-filter>--
>
<
intent-filter
>
<
!--<action android:name="android.intent.action.MAIN" />--
>
<
action
android:name=
"android.intent.action.MAIN"
/
>
<
!--<category android:name="android.intent.category.LAUNCHER" />--
>
<
category
android:name=
"android.intent.category.LAUNCHER"
/
>
<
!--</intent-filter>--
>
<
/intent-filter
>
<
!--</activity>--
>
<
/activity
>
</application>
</application>
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/MainActivity.java
View file @
61e53d36
package
com
.
widget
.
imagevideobanner
;
package
com
.
widget
.
imagevideobanner
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Environment
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
com.widget.imagevideobanner.banner.ImageVideoBanner
;
import
com.widget.imagevideobanner.banner.ImageVideoBanner
;
import
com.widget.imagevideobanner.bean.BannerBean
;
import
com.widget.imagevideobanner.bean.BannerBean
;
...
@@ -13,66 +11,34 @@ import java.util.ArrayList;
...
@@ -13,66 +11,34 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
private
List
<
BannerBean
>
list
=
new
ArrayList
<>();
private
List
<
BannerBean
>
list
=
new
ArrayList
<>();
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
ImageVideoBanner
banner
=
findViewById
(
R
.
id
.
banner
);
ImageVideoBanner
banner
=
findViewById
(
R
.
id
.
banner
);
// Button goSecondPager = findViewById(R.id.goSecondPager);
// goSecondPager.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// startActivity(new Intent(MainActivity.this, com.widget.imagevideobanner.MainActivity2.class));
// }
// });
setDatas
();
setDatas
();
banner
.
addData
(
list
);
banner
.
addData
(
list
);
banner
.
startBanner
();
banner
.
startBanner
();
}
}
private
void
setDatas
()
{
private
void
setDatas
()
{
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
BannerBean
listBean
=
new
BannerBean
();
BannerBean
listBean
=
new
BannerBean
();
if
(
i
==
0
)
{
if
(
i
==
0
)
{
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/Video_Compressed_converseBanner_2021_01_05_03_05_11_0.mp4"
;
// String url = Environment.getExternalStorageDirectory() + "/huarun/video/video_home_1_72m.mp4";
String
uri
=
"android.resource://"
+
getPackageName
()
+
"/"
+
R
.
raw
.
default_guide
;
listBean
.
setUrl
(
uri
);
listBean
.
setType
(
1
);
//图片类型 视频
list
.
add
(
listBean
);
}
else
if
(
i
==
1
){
listBean
.
setUrl
(
"http://pic11.nipic.com/20101201/4452735_182232064453_2.jpg"
);
listBean
.
setType
(
0
);
//图片类型 视频
list
.
add
(
listBean
);
}
else
if
(
i
==
2
){
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/huarun/video/video_scan.mp4"
;
// String uri = "android.resource://" + getPackageName() + "/" + R.raw.video_scan;
listBean
.
setUrl
(
url
);
listBean
.
setUrl
(
url
);
listBean
.
setType
(
1
);
//图片类型 视频
listBean
.
setType
(
1
);
list
.
add
(
listBean
);
list
.
add
(
listBean
);
}
else
if
(
i
==
3
){
}
else
if
(
i
==
1
)
{
listBean
.
setUrl
(
"http://120.26.246.123:18881/downloads/jjt1.jpg"
);
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/vertical_test.mp4"
;
listBean
.
setType
(
0
);
//图片类型 视频
listBean
.
setUrl
(
url
);
list
.
add
(
listBean
);
listBean
.
setType
(
1
);
}
else
if
(
i
==
4
){
listBean
.
setUrl
(
"http://120.26.246.123:18881/downloads/jjt2.jpg"
);
listBean
.
setType
(
0
);
//图片类型 视频
list
.
add
(
listBean
);
list
.
add
(
listBean
);
}
}
}
}
}
}
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
super
.
onNewIntent
(
intent
);
Log
.
e
(
"###"
,
"我是onNewIntent时间"
);
}
}
}
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoBanner.java
View file @
61e53d36
...
@@ -125,7 +125,10 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
...
@@ -125,7 +125,10 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
mmr
.
extractMetadata
(
FFmpegMediaMetadataRetriever
.
METADATA_KEY_ARTIST
);
mmr
.
extractMetadata
(
FFmpegMediaMetadataRetriever
.
METADATA_KEY_ARTIST
);
Bitmap
b
=
mmr
.
getFrameAtTime
();
// frame at 2 seconds
Bitmap
b
=
mmr
.
getFrameAtTime
();
// frame at 2 seconds
bannerBean
.
setLoadingImage
(
BitmapUtils
.
getBytes
(
b
));
bannerBean
.
setLoadingImage
(
BitmapUtils
.
getBytes
(
b
));
Bitmap
bx
=
BitmapUtils
.
createBlurBitmap
(
b
,
40
);
bannerBean
.
setLoadingBlurImage
(
BitmapUtils
.
getBytes
(
bx
));
b
.
recycle
();
b
.
recycle
();
bx
.
recycle
();
mmr
.
release
();
mmr
.
release
();
}
}
return
true
;
return
true
;
...
@@ -241,6 +244,18 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
...
@@ -241,6 +244,18 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
startBanner
(
0
);
startBanner
(
0
);
}
}
@Override
public
void
updateSize
(
BannerBean
bannerBean
)
{
if
(
mList
.
size
()
>
0
){
for
(
BannerBean
bean
:
mList
){
if
(
bannerBean
.
getUrl
().
equals
(
bean
.
getUrl
())){
bean
.
setHeight
(
bannerBean
.
getHeight
());
bean
.
setWidth
(
bannerBean
.
getWidth
());
}
}
}
}
private
final
class
ViewsPagerAdapter
extends
FragmentStatePagerAdapter
{
private
final
class
ViewsPagerAdapter
extends
FragmentStatePagerAdapter
{
private
com
.
widget
.
imagevideobanner
.
banner
.
ImageVideoFragment
fragment
;
private
com
.
widget
.
imagevideobanner
.
banner
.
ImageVideoFragment
fragment
;
private
FragmentManager
fm
;
private
FragmentManager
fm
;
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoFragment.java
View file @
61e53d36
...
@@ -11,6 +11,7 @@ import android.os.Handler;
...
@@ -11,6 +11,7 @@ import android.os.Handler;
import
android.os.Message
;
import
android.os.Message
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.constraint.ConstraintLayout
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -27,6 +28,8 @@ import com.widget.imagevideobanner.utils.BannerLogFileUtils;
...
@@ -27,6 +28,8 @@ import com.widget.imagevideobanner.utils.BannerLogFileUtils;
import
com.widget.imagevideobanner.utils.BitmapUtils
;
import
com.widget.imagevideobanner.utils.BitmapUtils
;
import
java.io.File
;
import
java.io.File
;
import
java.lang.ref.WeakReference
;
import
java.math.BigDecimal
;
public
class
ImageVideoFragment
extends
Fragment
{
public
class
ImageVideoFragment
extends
Fragment
{
...
@@ -38,39 +41,22 @@ public class ImageVideoFragment extends Fragment {
...
@@ -38,39 +41,22 @@ public class ImageVideoFragment extends Fragment {
// 视频是否循环播放
// 视频是否循环播放
private
boolean
loop
;
private
boolean
loop
;
private
ImageView
ivWaitLoading
;
private
ImageView
ivWaitLoading
;
private
ConstraintLayout
cVideoView
;
private
LinearLayout
llWaitLoading
;
private
LinearLayout
llWaitLoading
;
private
int
currentPosition
;
private
int
currentPosition
;
private
boolean
playerPaused
;
private
boolean
playerPaused
;
private
String
mUrl
;
private
String
mUrl
;
private
final
int
STOP_PLAYER
=
0x2000
;
private
static
final
int
STOP_PLAYER
=
0x2000
;
private
final
int
START_PLAYER
=
0x2001
;
private
static
final
int
START_PLAYER
=
0x2001
;
private
final
int
PAUSE_PLAYER
=
0x2002
;
private
static
final
int
PAUSE_PLAYER
=
0x2002
;
private
final
int
SET_VIDEO_URL
=
0x2003
;
private
static
final
int
SET_VIDEO_URL
=
0x2003
;
private
static
final
int
PROGRESS
=
0x2004
;
/**
/**
* 使用Handler是为了避免出现ANR异常
* 使用Handler是为了避免出现ANR异常
*/
*/
private
Handler
handler
=
new
Handler
()
{
private
Handler
handler
;
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
STOP_PLAYER:
stopPlayer
();
break
;
case
START_PLAYER:
startPlayer
();
break
;
case
PAUSE_PLAYER:
pausePlayer
();
break
;
case
SET_VIDEO_URL:
setVideoUrl
();
startPlayer
();
break
;
}
super
.
handleMessage
(
msg
);
}
};
@Override
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
...
@@ -79,6 +65,7 @@ public class ImageVideoFragment extends Fragment {
...
@@ -79,6 +65,7 @@ public class ImageVideoFragment extends Fragment {
bannerBean
=
(
BannerBean
)
bundle
.
getSerializable
(
"bannerBean"
);
bannerBean
=
(
BannerBean
)
bundle
.
getSerializable
(
"bannerBean"
);
loop
=
(
boolean
)
bundle
.
getBoolean
(
"loop"
);
loop
=
(
boolean
)
bundle
.
getBoolean
(
"loop"
);
Log
.
e
(
TAG
,
"type="
+
bannerBean
.
getType
()
+
",url="
+
bannerBean
.
getUrl
());
Log
.
e
(
TAG
,
"type="
+
bannerBean
.
getType
()
+
",url="
+
bannerBean
.
getUrl
());
handler
=
new
InnerHandler
(
this
);
}
}
@Nullable
@Nullable
...
@@ -104,7 +91,9 @@ public class ImageVideoFragment extends Fragment {
...
@@ -104,7 +91,9 @@ public class ImageVideoFragment extends Fragment {
mVideoView
=
view
.
findViewById
(
R
.
id
.
video_view
);
mVideoView
=
view
.
findViewById
(
R
.
id
.
video_view
);
ivWaitLoading
=
view
.
findViewById
(
R
.
id
.
iv_wait_loading_layout
);
ivWaitLoading
=
view
.
findViewById
(
R
.
id
.
iv_wait_loading_layout
);
llWaitLoading
=
view
.
findViewById
(
R
.
id
.
wait_loading_layout
);
llWaitLoading
=
view
.
findViewById
(
R
.
id
.
wait_loading_layout
);
setPicture
();
cVideoView
=
view
.
findViewById
(
R
.
id
.
cVideoView
);
setVideoBackground
();
setPicture
(
bannerBean
.
getWidth
(),
bannerBean
.
getHeight
());
initData
();
initData
();
}
}
}
else
{
}
else
{
...
@@ -113,6 +102,13 @@ public class ImageVideoFragment extends Fragment {
...
@@ -113,6 +102,13 @@ public class ImageVideoFragment extends Fragment {
return
view
;
return
view
;
}
}
public
void
setVideoBackground
(){
if
(
bannerBean
.
getLoadingImage
()
==
null
)
{
cVideoView
.
setBackgroundResource
(
R
.
drawable
.
guide_defaut
);
}
else
{
cVideoView
.
setBackground
(
BitmapUtils
.
bitmap2Drawable
(
BitmapUtils
.
getBitmap
(
bannerBean
.
getLoadingBlurImage
())));
}
}
/**
/**
* 设置加载视频的等待图片
* 设置加载视频的等待图片
...
@@ -135,12 +131,44 @@ public class ImageVideoFragment extends Fragment {
...
@@ -135,12 +131,44 @@ public class ImageVideoFragment extends Fragment {
}
}
}
}
/**
* 设置加载视频的等待图片
*/
public
void
setPicture
(
int
width
,
int
height
)
{
if
(
width
==
0
||
height
==
0
){
return
;
}
Log
.
e
(
"####"
,
"草"
+
width
+
" "
+
height
);
//设置设置尺寸
ConstraintLayout
.
LayoutParams
lp2
=
(
ConstraintLayout
.
LayoutParams
)
ivWaitLoading
.
getLayoutParams
();
lp2
.
height
=
height
;
lp2
.
width
=
width
;
ivWaitLoading
.
setLayoutParams
(
lp2
);
//视频未加载完成,使用菊花
if
(
bannerBean
.
getLoadingImage
()
==
null
)
{
if
(
bannerBean
.
getUrl
().
contains
(
"android.resource"
))
{
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setImageResource
(
R
.
drawable
.
guide_defaut
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
}
else
{
ivWaitLoading
.
setVisibility
(
View
.
GONE
);
llWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
}
}
else
{
//加载完成使用首帧图片
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setImageBitmap
(
BitmapUtils
.
getBitmap
(
bannerBean
.
getLoadingImage
()));
llWaitLoading
.
setVisibility
(
View
.
GONE
);
}
}
private
void
initData
()
{
private
void
initData
()
{
if
(
null
!=
mVideoView
)
{
if
(
null
!=
mVideoView
)
{
// mVideoView.setVideoPath(bannerBean.getUrl());
mVideoView
.
setAlpha
(
0
);
// mVideoView.setZOrderOnTop(true);
mVideoView
.
requestFocus
();
mVideoView
.
requestFocus
();
try
{
try
{
mVideoView
.
setVideoURI
(
Uri
.
parse
(
bannerBean
.
getUrl
()));
mVideoView
.
setVideoURI
(
Uri
.
parse
(
bannerBean
.
getUrl
()));
...
@@ -150,6 +178,8 @@ public class ImageVideoFragment extends Fragment {
...
@@ -150,6 +178,8 @@ public class ImageVideoFragment extends Fragment {
mVideoView
.
setOnCompletionListener
(
new
MediaPlayer
.
OnCompletionListener
()
{
mVideoView
.
setOnCompletionListener
(
new
MediaPlayer
.
OnCompletionListener
()
{
@Override
@Override
public
void
onCompletion
(
MediaPlayer
mp
)
{
public
void
onCompletion
(
MediaPlayer
mp
)
{
// mVideoView.setBackgroundColor(Color.TRANSPARENT);
// mVideoView.setVisibility(View.GONE);
mVideoView
.
pause
();
mVideoView
.
pause
();
if
(
null
!=
listener
)
{
if
(
null
!=
listener
)
{
listener
.
onVideoCompletion
(
mp
);
listener
.
onVideoCompletion
(
mp
);
...
@@ -160,12 +190,18 @@ public class ImageVideoFragment extends Fragment {
...
@@ -160,12 +190,18 @@ public class ImageVideoFragment extends Fragment {
mVideoView
.
setOnPreparedListener
(
new
MediaPlayer
.
OnPreparedListener
()
{
mVideoView
.
setOnPreparedListener
(
new
MediaPlayer
.
OnPreparedListener
()
{
@Override
@Override
public
void
onPrepared
(
MediaPlayer
mp
)
{
public
void
onPrepared
(
MediaPlayer
mp
)
{
//重新刷新大小
refreshPortraitScreen
(
mp
.
getVideoWidth
(),
mp
.
getVideoHeight
());
mp
.
setLooping
(
loop
);
mp
.
setLooping
(
loop
);
Log
.
e
(
TAG
,
"视频加载完成"
+
bannerBean
.
getUrl
());
Log
.
e
(
TAG
,
"视频加载完成"
+
bannerBean
.
getUrl
());
mp
.
setOnInfoListener
(
new
MediaPlayer
.
OnInfoListener
()
{
mp
.
setOnInfoListener
(
new
MediaPlayer
.
OnInfoListener
()
{
@Override
@Override
public
boolean
onInfo
(
MediaPlayer
mp
,
int
what
,
int
extra
)
{
public
boolean
onInfo
(
MediaPlayer
mp
,
int
what
,
int
extra
)
{
if
(
what
==
MediaPlayer
.
MEDIA_INFO_VIDEO_RENDERING_START
)
{
if
(
what
==
MediaPlayer
.
MEDIA_INFO_VIDEO_RENDERING_START
)
{
mVideoView
.
setAlpha
(
1
);
handler
.
sendEmptyMessage
(
PROGRESS
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
ivWaitLoading
.
setVisibility
(
View
.
GONE
);
ivWaitLoading
.
setVisibility
(
View
.
GONE
);
mVideoView
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
mVideoView
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
...
@@ -208,6 +244,44 @@ public class ImageVideoFragment extends Fragment {
...
@@ -208,6 +244,44 @@ public class ImageVideoFragment extends Fragment {
}
}
public
void
refreshPortraitScreen
(
int
width
,
int
height
)
{
int
mHeight
=
mVideoView
.
getHeight
();
int
mWidth
=
mVideoView
.
getWidth
();
BigDecimal
viewScale
=
new
BigDecimal
(
mWidth
+
""
)
.
divide
(
new
BigDecimal
(
mHeight
+
""
),
2
,
BigDecimal
.
ROUND_HALF_UP
);
BigDecimal
videoScale
=
new
BigDecimal
(
width
+
""
)
.
divide
(
new
BigDecimal
(
height
+
""
),
2
,
BigDecimal
.
ROUND_HALF_UP
);
if
(
viewScale
.
compareTo
(
videoScale
)
>=
0
){
//按照高度缩放
BigDecimal
heightScale
=
new
BigDecimal
(
mHeight
+
""
)
.
divide
(
new
BigDecimal
(
height
+
""
),
2
,
BigDecimal
.
ROUND_HALF_UP
);
height
=
mHeight
;
width
=
new
BigDecimal
(
width
+
""
).
multiply
(
heightScale
).
intValue
();
}
else
{
//按照宽度缩放
BigDecimal
widthScale
=
new
BigDecimal
(
mWidth
+
""
)
.
divide
(
new
BigDecimal
(
width
+
""
),
2
,
BigDecimal
.
ROUND_HALF_UP
);
width
=
mWidth
;
height
=
new
BigDecimal
(
height
+
""
).
multiply
(
widthScale
).
intValue
();
}
//设置videoview 宽高
ConstraintLayout
.
LayoutParams
lp
=
(
ConstraintLayout
.
LayoutParams
)
mVideoView
.
getLayoutParams
();
lp
.
height
=
height
;
lp
.
width
=
width
;
mVideoView
.
setLayoutParams
(
lp
);
if
(
bannerBean
.
getWidth
()
==
0
||
bannerBean
.
getHeight
()
==
0
){
bannerBean
.
setWidth
(
width
);
bannerBean
.
setHeight
(
height
);
listener
.
updateSize
(
bannerBean
);
}
}
private
void
setVideoUrl
()
{
private
void
setVideoUrl
()
{
String
url
=
bannerBean
.
getUrl
();
String
url
=
bannerBean
.
getUrl
();
...
@@ -251,7 +325,6 @@ public class ImageVideoFragment extends Fragment {
...
@@ -251,7 +325,6 @@ public class ImageVideoFragment extends Fragment {
private
void
stopPlayer
()
{
private
void
stopPlayer
()
{
Log
.
e
(
TAG
,
"stopPlayer"
);
Log
.
e
(
TAG
,
"stopPlayer"
);
if
(
null
!=
mVideoView
)
{
if
(
null
!=
mVideoView
)
{
mVideoView
.
stopPlayback
();
mVideoView
.
stopPlayback
();
handler
.
removeCallbacksAndMessages
(
null
);
handler
.
removeCallbacksAndMessages
(
null
);
}
}
...
@@ -265,10 +338,19 @@ public class ImageVideoFragment extends Fragment {
...
@@ -265,10 +338,19 @@ public class ImageVideoFragment extends Fragment {
return
false
;
return
false
;
}
}
public
int
getCurrentPosition
()
{
if
(
null
!=
mVideoView
)
{
return
mVideoView
.
getCurrentPosition
();
}
return
0
;
}
private
void
pausePlayer
()
{
private
void
pausePlayer
()
{
if
(
null
!=
mVideoView
)
{
if
(
null
!=
mVideoView
)
{
Log
.
e
(
TAG
,
"pausePlayer 当前进度是"
+
mVideoView
.
getCurrentPosition
());
Log
.
e
(
TAG
,
"pausePlayer 当前进度是"
+
mVideoView
.
getCurrentPosition
());
mVideoView
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
white
));
mVideoView
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
white
));
mVideoView
.
setAlpha
(
0
);
playerPaused
=
true
;
playerPaused
=
true
;
this
.
currentPosition
=
mVideoView
.
getCurrentPosition
();
this
.
currentPosition
=
mVideoView
.
getCurrentPosition
();
mVideoView
.
pause
();
mVideoView
.
pause
();
...
@@ -379,11 +461,40 @@ public class ImageVideoFragment extends Fragment {
...
@@ -379,11 +461,40 @@ public class ImageVideoFragment extends Fragment {
public
interface
OnVideoCompletionListener
{
public
interface
OnVideoCompletionListener
{
void
onVideoCompletion
(
MediaPlayer
mp
);
void
onVideoCompletion
(
MediaPlayer
mp
);
void
onError
(
MediaPlayer
mp
);
void
onError
(
MediaPlayer
mp
);
void
updateSize
(
BannerBean
bannerBean
);
}
}
public
void
setOnVideoCompletionListener
(
OnVideoCompletionListener
listener
)
{
public
void
setOnVideoCompletionListener
(
OnVideoCompletionListener
listener
)
{
this
.
listener
=
listener
;
this
.
listener
=
listener
;
}
}
private
static
class
InnerHandler
extends
Handler
{
private
final
WeakReference
<
Fragment
>
mFragment
;
public
InnerHandler
(
Fragment
fragment
){
mFragment
=
new
WeakReference
<
Fragment
>(
fragment
);
}
@Override
public
void
handleMessage
(
Message
msg
)
{
ImageVideoFragment
fragment
=(
ImageVideoFragment
)
mFragment
.
get
();
super
.
handleMessage
(
msg
);
if
(
fragment
!=
null
){
switch
(
msg
.
what
)
{
case
STOP_PLAYER:
fragment
.
stopPlayer
();
break
;
case
START_PLAYER:
fragment
.
startPlayer
();
break
;
case
PAUSE_PLAYER:
fragment
.
pausePlayer
();
break
;
case
SET_VIDEO_URL:
fragment
.
setVideoUrl
();
fragment
.
startPlayer
();
break
;
}
}
}
}
}
}
imageVideoBanner/src/main/java/com/widget/imagevideobanner/bean/BannerBean.java
View file @
61e53d36
...
@@ -6,6 +6,33 @@ public class BannerBean implements Serializable {
...
@@ -6,6 +6,33 @@ public class BannerBean implements Serializable {
private
String
url
;
private
String
url
;
private
int
type
;
private
int
type
;
private
byte
[]
loadingImage
;
private
byte
[]
loadingImage
;
private
byte
[]
loadingBlurImage
;
private
int
width
;
private
int
height
;
public
int
getWidth
()
{
return
width
;
}
public
void
setWidth
(
int
width
)
{
this
.
width
=
width
;
}
public
int
getHeight
()
{
return
height
;
}
public
void
setHeight
(
int
height
)
{
this
.
height
=
height
;
}
public
byte
[]
getLoadingBlurImage
()
{
return
loadingBlurImage
;
}
public
void
setLoadingBlurImage
(
byte
[]
loadingBlurImage
)
{
this
.
loadingBlurImage
=
loadingBlurImage
;
}
public
byte
[]
getLoadingImage
()
{
public
byte
[]
getLoadingImage
()
{
return
loadingImage
;
return
loadingImage
;
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/utils/BitmapUtils.java
View file @
61e53d36
...
@@ -2,6 +2,8 @@ package com.widget.imagevideobanner.utils;
...
@@ -2,6 +2,8 @@ package com.widget.imagevideobanner.utils;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.os.Environment
;
import
android.os.Environment
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
...
@@ -42,5 +44,204 @@ public class BitmapUtils {
...
@@ -42,5 +44,204 @@ public class BitmapUtils {
}
}
}
}
/**
* 传递bitmap 传递模糊半径 返回一个被模糊的bitmap
* 比较耗时
* @param sentBitmap
* @param radius
* @return
*/
public
static
Bitmap
createBlurBitmap
(
Bitmap
sentBitmap
,
int
radius
)
{
Bitmap
bitmap
=
sentBitmap
.
copy
(
sentBitmap
.
getConfig
(),
true
);
if
(
radius
<
1
)
{
return
(
null
);
}
int
w
=
bitmap
.
getWidth
();
int
h
=
bitmap
.
getHeight
();
int
[]
pix
=
new
int
[
w
*
h
];
bitmap
.
getPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
int
wm
=
w
-
1
;
int
hm
=
h
-
1
;
int
wh
=
w
*
h
;
int
div
=
radius
+
radius
+
1
;
int
r
[]
=
new
int
[
wh
];
int
g
[]
=
new
int
[
wh
];
int
b
[]
=
new
int
[
wh
];
int
rsum
,
gsum
,
bsum
,
x
,
y
,
i
,
p
,
yp
,
yi
,
yw
;
int
vmin
[]
=
new
int
[
Math
.
max
(
w
,
h
)];
int
divsum
=
(
div
+
1
)
>>
1
;
divsum
*=
divsum
;
int
dv
[]
=
new
int
[
256
*
divsum
];
for
(
i
=
0
;
i
<
256
*
divsum
;
i
++)
{
dv
[
i
]
=
(
i
/
divsum
);
}
yw
=
yi
=
0
;
int
[][]
stack
=
new
int
[
div
][
3
];
int
stackpointer
;
int
stackstart
;
int
[]
sir
;
int
rbs
;
int
r1
=
radius
+
1
;
int
routsum
,
goutsum
,
boutsum
;
int
rinsum
,
ginsum
,
binsum
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
p
=
pix
[
yi
+
Math
.
min
(
wm
,
Math
.
max
(
i
,
0
))];
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
sir
[
0
]
*
rbs
;
gsum
+=
sir
[
1
]
*
rbs
;
bsum
+=
sir
[
2
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
}
stackpointer
=
radius
;
for
(
x
=
0
;
x
<
w
;
x
++)
{
r
[
yi
]
=
dv
[
rsum
];
g
[
yi
]
=
dv
[
gsum
];
b
[
yi
]
=
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
y
==
0
)
{
vmin
[
x
]
=
Math
.
min
(
x
+
radius
+
1
,
wm
);
}
p
=
pix
[
yw
+
vmin
[
x
]];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[(
stackpointer
)
%
div
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
++;
}
yw
+=
w
;
}
for
(
x
=
0
;
x
<
w
;
x
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
yp
=
-
radius
*
w
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
yi
=
Math
.
max
(
0
,
yp
)
+
x
;
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
r
[
yi
];
sir
[
1
]
=
g
[
yi
];
sir
[
2
]
=
b
[
yi
];
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
r
[
yi
]
*
rbs
;
gsum
+=
g
[
yi
]
*
rbs
;
bsum
+=
b
[
yi
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
if
(
i
<
hm
)
{
yp
+=
w
;
}
}
yi
=
x
;
stackpointer
=
radius
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
pix
[
yi
]
=
(
0xff000000
&
pix
[
yi
])
|
(
dv
[
rsum
]
<<
16
)
|
(
dv
[
gsum
]
<<
8
)
|
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
x
==
0
)
{
vmin
[
y
]
=
Math
.
min
(
y
+
r1
,
hm
)
*
w
;
}
p
=
x
+
vmin
[
y
];
sir
[
0
]
=
r
[
p
];
sir
[
1
]
=
g
[
p
];
sir
[
2
]
=
b
[
p
];
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[
stackpointer
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
+=
w
;
}
}
bitmap
.
setPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
return
(
bitmap
);
}
public
static
Drawable
bitmap2Drawable
(
Bitmap
bitmap
)
{
@SuppressWarnings
(
"deprecation"
)
BitmapDrawable
bd
=
new
BitmapDrawable
(
bitmap
);
Drawable
d
=
(
Drawable
)
bd
;
return
d
;
}
}
}
imageVideoBanner/src/main/res/layout/item_video_view.xml
View file @
61e53d36
...
@@ -2,21 +2,30 @@
...
@@ -2,21 +2,30 @@
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
android:id=
"@+id/cVideoView"
>
<VideoView
<VideoView
android:id=
"@+id/video_view"
android:id=
"@+id/video_view"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
android:layout_height=
"match_parent"
android:visibility=
"visible"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
/>
<ImageView
<ImageView
android:id=
"@+id/iv_wait_loading_layout"
android:id=
"@+id/iv_wait_loading_layout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:scaleType=
"fitXY"
android:scaleType=
"fitXY"
android:background=
"@android:color/white"
>
android:visibility=
"gone"
</ImageView>
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:background=
"@android:color/white"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/wait_loading_layout"
android:id=
"@+id/wait_loading_layout"
...
@@ -28,6 +37,7 @@
...
@@ -28,6 +37,7 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
android:gravity=
"center"
android:gravity=
"center"
android:background=
"@color/white"
android:background=
"@color/white"
android:visibility=
"invisible"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<LinearLayout
<LinearLayout
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment