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
4555129f
Commit
4555129f
authored
Jan 20, 2021
by
gaodapeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化了bitmap的回收
parent
d3c90cdb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
65 deletions
+84
-65
ImageVideoBanner.java
.../com/widget/imagevideobanner/banner/ImageVideoBanner.java
+47
-45
ImageVideoFragment.java
...om/widget/imagevideobanner/banner/ImageVideoFragment.java
+37
-20
No files found.
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoBanner.java
View file @
4555129f
This diff is collapsed.
Click to expand it.
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoFragment.java
View file @
4555129f
package
com
.
widget
.
imagevideobanner
.
banner
;
package
com
.
widget
.
imagevideobanner
.
banner
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.media.MediaPlayer
;
import
android.media.MediaPlayer
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
...
@@ -88,10 +91,10 @@ public class ImageVideoFragment extends Fragment {
...
@@ -88,10 +91,10 @@ public class ImageVideoFragment extends Fragment {
view
=
LayoutInflater
.
from
(
getActivity
()).
inflate
(
R
.
layout
.
item_image_view
,
container
,
false
);
view
=
LayoutInflater
.
from
(
getActivity
()).
inflate
(
R
.
layout
.
item_image_view
,
container
,
false
);
ImageView
imageView
=
view
.
findViewById
(
R
.
id
.
iv
);
ImageView
imageView
=
view
.
findViewById
(
R
.
id
.
iv
);
File
file
=
new
File
(
bannerBean
.
getUrl
());
File
file
=
new
File
(
bannerBean
.
getUrl
());
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
Glide
.
with
(
container
.
getContext
()).
load
(
file
)
Glide
.
with
(
container
.
getContext
()).
load
(
file
)
.
into
(
imageView
);
.
into
(
imageView
);
}
else
{
}
else
{
Glide
.
with
(
container
.
getContext
()).
load
(
bannerBean
.
getUrl
())
Glide
.
with
(
container
.
getContext
()).
load
(
bannerBean
.
getUrl
())
.
into
(
imageView
);
.
into
(
imageView
);
}
}
...
@@ -116,20 +119,19 @@ public class ImageVideoFragment extends Fragment {
...
@@ -116,20 +119,19 @@ public class ImageVideoFragment extends Fragment {
*/
*/
public
void
setPicture
()
{
public
void
setPicture
()
{
//视频未加载完成,使用菊花
//视频未加载完成,使用菊花
if
(
bannerBean
.
getLoadingImage
()
==
null
)
{
if
(
bannerBean
.
getLoadingImage
()
==
null
)
{
if
(
bannerBean
.
getUrl
().
contains
(
"android.resource"
))
{
if
(
bannerBean
.
getUrl
().
contains
(
"android.resource"
))
{
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setImageResource
(
R
.
drawable
.
guide_defaut
);
ivWaitLoading
.
setImageResource
(
R
.
drawable
.
guide_defaut
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
}
else
{
}
else
{
ivWaitLoading
.
setVisibility
(
View
.
GONE
);
ivWaitLoading
.
setVisibility
(
View
.
GONE
);
llWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
llWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
}
}
}
else
{
//加载完成使用首帧图片
}
else
{
//加载完成使用首帧图片
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setVisibility
(
View
.
VISIBLE
);
ivWaitLoading
.
setImageBitmap
(
BitmapUtils
.
getBitmap
(
bannerBean
.
getLoadingImage
()));
ivWaitLoading
.
setImageBitmap
(
BitmapUtils
.
getBitmap
(
bannerBean
.
getLoadingImage
()));
llWaitLoading
.
setVisibility
(
View
.
GONE
);
llWaitLoading
.
setVisibility
(
View
.
GONE
);
}
}
}
}
...
@@ -142,7 +144,7 @@ public class ImageVideoFragment extends Fragment {
...
@@ -142,7 +144,7 @@ public class ImageVideoFragment extends Fragment {
mVideoView
.
requestFocus
();
mVideoView
.
requestFocus
();
try
{
try
{
mVideoView
.
setVideoURI
(
Uri
.
parse
(
bannerBean
.
getUrl
()));
mVideoView
.
setVideoURI
(
Uri
.
parse
(
bannerBean
.
getUrl
()));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
}
}
mVideoView
.
setOnCompletionListener
(
new
MediaPlayer
.
OnCompletionListener
()
{
mVideoView
.
setOnCompletionListener
(
new
MediaPlayer
.
OnCompletionListener
()
{
...
@@ -221,7 +223,7 @@ public class ImageVideoFragment extends Fragment {
...
@@ -221,7 +223,7 @@ public class ImageVideoFragment extends Fragment {
public
void
startPlayer
()
{
public
void
startPlayer
()
{
if
(
null
!=
mVideoView
)
{
if
(
null
!=
mVideoView
)
{
// setWaitLoading();
// setWaitLoading();
Log
.
e
(
TAG
,
"startPlayer "
+
currentPosition
);
Log
.
e
(
TAG
,
"startPlayer "
+
currentPosition
);
mVideoView
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
mVideoView
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
mVideoView
.
seekTo
(
currentPosition
);
mVideoView
.
seekTo
(
currentPosition
);
mVideoView
.
start
();
mVideoView
.
start
();
...
@@ -265,7 +267,7 @@ public class ImageVideoFragment extends Fragment {
...
@@ -265,7 +267,7 @@ public class ImageVideoFragment extends Fragment {
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
));
playerPaused
=
true
;
playerPaused
=
true
;
this
.
currentPosition
=
mVideoView
.
getCurrentPosition
();
this
.
currentPosition
=
mVideoView
.
getCurrentPosition
();
...
@@ -351,6 +353,21 @@ public class ImageVideoFragment extends Fragment {
...
@@ -351,6 +353,21 @@ public class ImageVideoFragment extends Fragment {
sendPauseVideoMsg
();
sendPauseVideoMsg
();
}
}
@Override
public
void
onDestroyView
()
{
if
(
ivWaitLoading
!=
null
)
{
Drawable
drawable
=
ivWaitLoading
.
getDrawable
();
ivWaitLoading
.
setImageDrawable
(
null
);
if
(
drawable
instanceof
BitmapDrawable
)
{
Bitmap
bm
=
((
BitmapDrawable
)
drawable
).
getBitmap
();
if
(!
bm
.
isRecycled
())
{
bm
.
recycle
();
}
}
}
super
.
onDestroyView
();
}
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
super
.
onDestroy
();
super
.
onDestroy
();
...
...
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