正在显示
7 个修改的文件
包含
504 行增加
和
129 行删除
1 | package com.yinhebairong.clasmanage.ui; | 1 | package com.yinhebairong.clasmanage.ui; |
2 | 2 | ||
3 | import android.Manifest; | 3 | import android.Manifest; |
4 | -import android.app.Activity; | ||
5 | import android.app.Service; | 4 | import android.app.Service; |
6 | import android.content.pm.PackageManager; | 5 | import android.content.pm.PackageManager; |
7 | -import android.content.res.Configuration; | ||
8 | -import android.graphics.Color; | ||
9 | import android.media.AudioManager; | 6 | import android.media.AudioManager; |
10 | import android.media.MediaPlayer; | 7 | import android.media.MediaPlayer; |
11 | import android.os.Bundle; | 8 | import android.os.Bundle; |
12 | -import android.os.Handler; | ||
13 | -import android.os.Message; | ||
14 | import android.support.annotation.NonNull; | 9 | import android.support.annotation.NonNull; |
15 | import android.support.v4.app.ActivityCompat; | 10 | import android.support.v4.app.ActivityCompat; |
16 | import android.support.v4.content.ContextCompat; | 11 | import android.support.v4.content.ContextCompat; |
17 | import android.support.v7.app.AppCompatActivity; | 12 | import android.support.v7.app.AppCompatActivity; |
18 | import android.view.View; | 13 | import android.view.View; |
19 | -import android.widget.Button; | ||
20 | import android.widget.ImageButton; | 14 | import android.widget.ImageButton; |
21 | import android.widget.ImageView; | 15 | import android.widget.ImageView; |
22 | import android.widget.SeekBar; | 16 | import android.widget.SeekBar; |
23 | import android.widget.TextView; | 17 | import android.widget.TextView; |
24 | import android.widget.Toast; | 18 | import android.widget.Toast; |
25 | 19 | ||
26 | -import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; | ||
27 | -import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack; | ||
28 | -import com.shuyu.gsyvideoplayer.listener.LockClickListener; | ||
29 | -import com.shuyu.gsyvideoplayer.utils.OrientationUtils; | ||
30 | -import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer; | ||
31 | import com.yinhebairong.clasmanage.R; | 20 | import com.yinhebairong.clasmanage.R; |
32 | -import com.yinhebairong.clasmanage.base.BaseActivity; | ||
33 | -import com.yinhebairong.clasmanage.base.instant.Layout; | ||
34 | -import com.yinhebairong.clasmanage.base.instant.TopNavigationBar; | ||
35 | -import com.yinhebairong.clasmanage.base.instant.slideslip.SlideLip; | ||
36 | -import com.yinhebairong.clasmanage.ui.jxt.activity.HD.Fbhd_Activity; | ||
37 | -import com.yinhebairong.clasmanage.view.DebugLog; | ||
38 | - | ||
39 | -import java.io.IOException; | ||
40 | -import java.lang.ref.WeakReference; | 21 | + |
41 | import java.text.SimpleDateFormat; | 22 | import java.text.SimpleDateFormat; |
42 | -import java.util.Date; | ||
43 | import java.util.Timer; | 23 | import java.util.Timer; |
44 | import java.util.TimerTask; | 24 | import java.util.TimerTask; |
45 | -import java.util.concurrent.ExecutorService; | ||
46 | -import java.util.concurrent.Executors; | ||
47 | - | ||
48 | -import butterknife.BindView; | ||
49 | -import butterknife.ButterKnife; | ||
50 | -import butterknife.OnClick; | ||
51 | 25 | ||
52 | public class AudioAndVideoPlayActivity extends AppCompatActivity implements View.OnClickListener{ | 26 | public class AudioAndVideoPlayActivity extends AppCompatActivity implements View.OnClickListener{ |
53 | - private ImageButton play, pause, stop, volume_plus, volume_decrease; | 27 | + private ImageButton pause, stop, volume_plus, volume_decrease; |
28 | + private ImageView play; | ||
54 | private TextView musicName, musicLength, musicCur; | 29 | private TextView musicName, musicLength, musicCur; |
55 | private SeekBar seekBar; | 30 | private SeekBar seekBar; |
56 | 31 | ||
@@ -70,13 +45,13 @@ public class AudioAndVideoPlayActivity extends AppCompatActivity implements View | @@ -70,13 +45,13 @@ public class AudioAndVideoPlayActivity extends AppCompatActivity implements View | ||
70 | @Override | 45 | @Override |
71 | protected void onCreate(Bundle savedInstanceState) { | 46 | protected void onCreate(Bundle savedInstanceState) { |
72 | super.onCreate(savedInstanceState); | 47 | super.onCreate(savedInstanceState); |
73 | - setContentView(R.layout.activity_audio); | 48 | + setContentView(R.layout.pop_audio); |
74 | 49 | ||
75 | audioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE); | 50 | audioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE); |
76 | 51 | ||
77 | format = new SimpleDateFormat("mm:ss"); | 52 | format = new SimpleDateFormat("mm:ss"); |
78 | 53 | ||
79 | - play = (ImageButton) findViewById(R.id.play); | 54 | + play = (ImageView) findViewById(R.id.play); |
80 | pause = (ImageButton) findViewById(R.id.pause); | 55 | pause = (ImageButton) findViewById(R.id.pause); |
81 | stop = (ImageButton) findViewById(R.id.stop); | 56 | stop = (ImageButton) findViewById(R.id.stop); |
82 | volume_plus = (ImageButton) findViewById(R.id.volume_plus); | 57 | volume_plus = (ImageButton) findViewById(R.id.volume_plus); |
1 | package com.yinhebairong.clasmanage.ui; | 1 | package com.yinhebairong.clasmanage.ui; |
2 | 2 | ||
3 | +import android.content.Intent; | ||
3 | import android.content.res.Configuration; | 4 | import android.content.res.Configuration; |
4 | import android.graphics.Color; | 5 | import android.graphics.Color; |
5 | import android.media.MediaPlayer; | 6 | import android.media.MediaPlayer; |
6 | import android.os.Handler; | 7 | import android.os.Handler; |
7 | import android.os.Message; | 8 | import android.os.Message; |
9 | +import android.view.Gravity; | ||
10 | +import android.view.LayoutInflater; | ||
8 | import android.view.View; | 11 | import android.view.View; |
12 | +import android.view.WindowManager; | ||
9 | import android.widget.Button; | 13 | import android.widget.Button; |
10 | import android.widget.ImageView; | 14 | import android.widget.ImageView; |
15 | +import android.widget.PopupWindow; | ||
11 | import android.widget.SeekBar; | 16 | import android.widget.SeekBar; |
12 | 17 | ||
13 | import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; | 18 | import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder; |
@@ -20,7 +25,11 @@ import com.yinhebairong.clasmanage.base.BaseActivity; | @@ -20,7 +25,11 @@ import com.yinhebairong.clasmanage.base.BaseActivity; | ||
20 | import com.yinhebairong.clasmanage.base.instant.Layout; | 25 | import com.yinhebairong.clasmanage.base.instant.Layout; |
21 | import com.yinhebairong.clasmanage.base.instant.TopNavigationBar; | 26 | import com.yinhebairong.clasmanage.base.instant.TopNavigationBar; |
22 | import com.yinhebairong.clasmanage.base.instant.slideslip.SlideLip; | 27 | import com.yinhebairong.clasmanage.base.instant.slideslip.SlideLip; |
28 | +import com.yinhebairong.clasmanage.m.M; | ||
29 | +import com.yinhebairong.clasmanage.ui.jxt.activity.HD.Fbhd_Activity; | ||
30 | +import com.yinhebairong.clasmanage.ui.jxt.activity.HD.Hdxq_Activity; | ||
23 | import com.yinhebairong.clasmanage.view.DebugLog; | 31 | import com.yinhebairong.clasmanage.view.DebugLog; |
32 | +import com.yinhebairong.clasmanage.view.pop.AudioPopupWindow; | ||
24 | 33 | ||
25 | import java.io.IOException; | 34 | import java.io.IOException; |
26 | import java.util.concurrent.ExecutorService; | 35 | import java.util.concurrent.ExecutorService; |
@@ -36,12 +45,10 @@ import butterknife.OnClick; | @@ -36,12 +45,10 @@ import butterknife.OnClick; | ||
36 | public class AudioAndVideoPlayActivity2 extends BaseActivity { | 45 | public class AudioAndVideoPlayActivity2 extends BaseActivity { |
37 | @BindView(R.id.include_back) | 46 | @BindView(R.id.include_back) |
38 | ImageView includeBack; | 47 | ImageView includeBack; |
48 | + @BindView(R.id.include_right) | ||
49 | + ImageView include_right; | ||
39 | @BindView(R.id.videoplay) | 50 | @BindView(R.id.videoplay) |
40 | StandardGSYVideoPlayer videoplay; | 51 | StandardGSYVideoPlayer videoplay; |
41 | - @BindView(R.id.btn_bofang) | ||
42 | - Button btn_bofang; | ||
43 | - @BindView(R.id.seekBar1) | ||
44 | - SeekBar seekBar1; | ||
45 | private boolean isPlay; | 52 | private boolean isPlay; |
46 | private boolean isPause; | 53 | private boolean isPause; |
47 | GSYVideoOptionBuilder gsyVideoOption; | 54 | GSYVideoOptionBuilder gsyVideoOption; |
@@ -74,12 +81,89 @@ public class AudioAndVideoPlayActivity2 extends BaseActivity { | @@ -74,12 +81,89 @@ public class AudioAndVideoPlayActivity2 extends BaseActivity { | ||
74 | }); | 81 | }); |
75 | } | 82 | } |
76 | 83 | ||
77 | - @OnClick({}) | 84 | + @OnClick({R.id.include_right}) |
78 | public void onViewClicked(View view) { | 85 | public void onViewClicked(View view) { |
79 | switch (view.getId()) { | 86 | switch (view.getId()) { |
87 | + case R.id.include_right: | ||
88 | + optionPop(); | ||
89 | + break; | ||
80 | } | 90 | } |
81 | } | 91 | } |
82 | 92 | ||
93 | + PopupWindow downloadPopupwindow; | ||
94 | + | ||
95 | + /** | ||
96 | + * 右上角pop | ||
97 | + */ | ||
98 | + private void optionPop() { | ||
99 | + View view = LayoutInflater.from(AudioAndVideoPlayActivity2.this).inflate(R.layout.popup_download, null); | ||
100 | + // 弹窗 | ||
101 | + downloadPopupwindow = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); | ||
102 | + downloadPopupwindow.setOutsideTouchable(true); | ||
103 | + downloadPopupwindow.setTouchable(true); | ||
104 | + downloadPopupwindow.setFocusable(true); | ||
105 | + downloadPopupwindow.setBackgroundDrawable(getResources().getDrawable(R.color.color_tm)); | ||
106 | + downloadPopupwindow.showAtLocation(view, Gravity.BOTTOM, 0, M.getNavigationBarHeight(this)); | ||
107 | + view.findViewById(R.id.tv_download).setOnClickListener(new View.OnClickListener() { | ||
108 | + @Override | ||
109 | + public void onClick(View v) { | ||
110 | + downloadPopupwindow.dismiss(); | ||
111 | + } | ||
112 | + }); | ||
113 | + | ||
114 | + view.findViewById(R.id.tv_cancal).setOnClickListener(new View.OnClickListener() { | ||
115 | + @Override | ||
116 | + public void onClick(View v) { | ||
117 | + downloadPopupwindow.dismiss(); | ||
118 | + } | ||
119 | + }); | ||
120 | + view.findViewById(R.id.tv_zhuanfa).setOnClickListener(new View.OnClickListener() { | ||
121 | + @Override | ||
122 | + public void onClick(View v) { | ||
123 | + audioPop(); | ||
124 | + downloadPopupwindow.dismiss(); | ||
125 | + } | ||
126 | + }); | ||
127 | + } | ||
128 | + | ||
129 | + PopupWindow audioPop; | ||
130 | + AudioPopupWindow customPopupWindow; | ||
131 | + | ||
132 | + /** | ||
133 | + * 音频pop | ||
134 | + */ | ||
135 | + private void audioPop() { | ||
136 | + customPopupWindow = new AudioPopupWindow(AudioAndVideoPlayActivity2.this); | ||
137 | + customPopupWindow.start("http://class.ynsdfx.com/uploads/20200410/4958b3dc56895cedffbe20ca86869c4c.wav","试试"); | ||
138 | +// View view = LayoutInflater.from(AudioAndVideoPlayActivity2.this).inflate(R.layout.popup_hdxq, null); | ||
139 | +// // 弹窗 | ||
140 | +// audioPop = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); | ||
141 | +// audioPop.setOutsideTouchable(true); | ||
142 | +// audioPop.setTouchable(true); | ||
143 | +// audioPop.setFocusable(true); | ||
144 | +// audioPop.setBackgroundDrawable(getResources().getDrawable(R.color.color_tm)); | ||
145 | +// audioPop.showAtLocation(view, Gravity.BOTTOM, 0, M.getNavigationBarHeight(this)); | ||
146 | +// view.findViewById(R.id.tv_download).setOnClickListener(new View.OnClickListener() { | ||
147 | +// @Override | ||
148 | +// public void onClick(View v) { | ||
149 | +// audioPop.dismiss(); | ||
150 | +// } | ||
151 | +// }); | ||
152 | +// | ||
153 | +// view.findViewById(R.id.tv_cancal).setOnClickListener(new View.OnClickListener() { | ||
154 | +// @Override | ||
155 | +// public void onClick(View v) { | ||
156 | +// audioPop.dismiss(); | ||
157 | +// } | ||
158 | +// }); | ||
159 | +// view.findViewById(R.id.tv_zhuanfa).setOnClickListener(new View.OnClickListener() { | ||
160 | +// @Override | ||
161 | +// public void onClick(View v) { | ||
162 | +// audioPop.dismiss(); | ||
163 | +// } | ||
164 | +// }); | ||
165 | + } | ||
166 | + | ||
83 | private void setplay(GSYVideoOptionBuilder gsyVideoOption, String url) { | 167 | private void setplay(GSYVideoOptionBuilder gsyVideoOption, String url) { |
84 | gsyVideoOption | 168 | gsyVideoOption |
85 | .setIsTouchWiget(true) | 169 | .setIsTouchWiget(true) |
@@ -140,13 +224,15 @@ public class AudioAndVideoPlayActivity2 extends BaseActivity { | @@ -140,13 +224,15 @@ public class AudioAndVideoPlayActivity2 extends BaseActivity { | ||
140 | @Override | 224 | @Override |
141 | protected void onDestroy() { | 225 | protected void onDestroy() { |
142 | super.onDestroy(); | 226 | super.onDestroy(); |
143 | - if (isPlay&&videoplay!=null) { | 227 | + if (isPlay && videoplay != null) { |
144 | videoplay.getCurrentPlayer().release(); | 228 | videoplay.getCurrentPlayer().release(); |
145 | } | 229 | } |
146 | if (orientationUtils != null) { | 230 | if (orientationUtils != null) { |
147 | orientationUtils.releaseListener(); | 231 | orientationUtils.releaseListener(); |
148 | } | 232 | } |
149 | - | 233 | + if (customPopupWindow != null) { |
234 | + customPopupWindow.destroy(); | ||
235 | + } | ||
150 | } | 236 | } |
151 | 237 | ||
152 | 238 |
@@ -72,7 +72,7 @@ public class HomeFragment extends BaseFragment { | @@ -72,7 +72,7 @@ public class HomeFragment extends BaseFragment { | ||
72 | startActivitys(QmpmActivity.class); | 72 | startActivitys(QmpmActivity.class); |
73 | break; | 73 | break; |
74 | case R.id.home_kcb: // 课程表 | 74 | case R.id.home_kcb: // 课程表 |
75 | - startActivitys(AudioAndVideoPlayActivity.class); | 75 | + startActivitys(AudioAndVideoPlayActivity2.class); |
76 | break; | 76 | break; |
77 | // case R.id.home_wdjk: // 我的监考 | 77 | // case R.id.home_wdjk: // 我的监考 |
78 | // startActivitys(WdjkActivity.class); | 78 | // startActivitys(WdjkActivity.class); |
1 | +package com.yinhebairong.clasmanage.view.pop; | ||
2 | + | ||
3 | +import android.Manifest; | ||
4 | +import android.annotation.SuppressLint; | ||
5 | +import android.app.Activity; | ||
6 | +import android.app.Service; | ||
7 | +import android.content.Context; | ||
8 | +import android.content.pm.PackageManager; | ||
9 | +import android.graphics.drawable.ColorDrawable; | ||
10 | +import android.media.AudioManager; | ||
11 | +import android.media.MediaPlayer; | ||
12 | +import android.support.v4.app.ActivityCompat; | ||
13 | +import android.support.v4.content.ContextCompat; | ||
14 | +import android.view.Gravity; | ||
15 | +import android.view.LayoutInflater; | ||
16 | +import android.view.MotionEvent; | ||
17 | +import android.view.View; | ||
18 | +import android.view.ViewGroup; | ||
19 | +import android.view.WindowManager; | ||
20 | +import android.widget.Button; | ||
21 | +import android.widget.ImageView; | ||
22 | +import android.widget.LinearLayout; | ||
23 | +import android.widget.PopupWindow; | ||
24 | +import android.widget.RelativeLayout; | ||
25 | +import android.widget.SeekBar; | ||
26 | +import android.widget.TextView; | ||
27 | + | ||
28 | +import com.yinhebairong.clasmanage.R; | ||
29 | +import com.yinhebairong.clasmanage.m.M; | ||
30 | +import com.yinhebairong.clasmanage.ui.AudioAndVideoPlayActivity; | ||
31 | + | ||
32 | +import java.text.SimpleDateFormat; | ||
33 | +import java.util.Timer; | ||
34 | +import java.util.TimerTask; | ||
35 | + | ||
36 | +/** | ||
37 | + * Time: 4/13/2020 10:04 | ||
38 | + * Author: TAO | ||
39 | + * Description: | ||
40 | + */ | ||
41 | +public class AudioPopupWindow extends PopupWindow implements View.OnClickListener { | ||
42 | + private View mPopView; | ||
43 | + private ImageView play; | ||
44 | + private TextView tv_downloud, musicName, musicLength, musicCur; | ||
45 | + private LinearLayout id_pop_layout; | ||
46 | + private SeekBar seekBar; | ||
47 | + private MediaPlayer mediaPlayer = new MediaPlayer(); | ||
48 | + private AudioManager audioManager; | ||
49 | + private Timer timer; | ||
50 | + int maxVolume, currentVolume; | ||
51 | + private boolean isSeekBarChanging;//互斥变量,防止进度条与定时器冲突。 | ||
52 | + private int currentPosition;//当前音乐播放的进度 | ||
53 | + SimpleDateFormat format; | ||
54 | + | ||
55 | + private Context mContext; | ||
56 | + | ||
57 | + public AudioPopupWindow(Context context) { | ||
58 | + super(context); | ||
59 | + mContext = context; | ||
60 | + init(context); | ||
61 | + setPopupWindow(); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 开始 | ||
66 | + * | ||
67 | + * @param url | ||
68 | + * @param name | ||
69 | + */ | ||
70 | + public void start(String url, String name) { | ||
71 | + initMediaPlayer(url, name);//初始化mediaplayer | ||
72 | + showAtLocation(mPopView, Gravity.BOTTOM, 0, M.getNavigationBarHeight(mContext)); | ||
73 | + } | ||
74 | + | ||
75 | + private void init(Context context) { | ||
76 | + LayoutInflater inflater = LayoutInflater.from(context); | ||
77 | + mPopView = inflater.inflate(R.layout.pop_audio, null); | ||
78 | + | ||
79 | + play = (ImageView) mPopView.findViewById(R.id.play); | ||
80 | + tv_downloud = (TextView) mPopView.findViewById(R.id.tv_downloud); | ||
81 | + musicName = (TextView) mPopView.findViewById(R.id.music_name); | ||
82 | + tv_downloud = (TextView) mPopView.findViewById(R.id.tv_downloud); | ||
83 | + musicLength = (TextView) mPopView.findViewById(R.id.music_length); | ||
84 | + musicCur = (TextView) mPopView.findViewById(R.id.music_cur); | ||
85 | + id_pop_layout = (LinearLayout) mPopView.findViewById(R.id.id_pop_layout); | ||
86 | + play.setOnClickListener(this); | ||
87 | + id_pop_layout.setOnClickListener(this); | ||
88 | + | ||
89 | + audioManager = (AudioManager) ((Activity) mContext).getSystemService(Service.AUDIO_SERVICE); | ||
90 | + format = new SimpleDateFormat("mm:ss"); | ||
91 | + seekBar = (SeekBar) mPopView.findViewById(R.id.seekBar); | ||
92 | + seekBar.setOnSeekBarChangeListener(new MySeekBar()); | ||
93 | + | ||
94 | + tv_downloud.setOnClickListener(this); | ||
95 | + if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) != | ||
96 | + PackageManager.PERMISSION_GRANTED) { | ||
97 | + ActivityCompat.requestPermissions((Activity) mContext, | ||
98 | + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); | ||
99 | + } else { | ||
100 | + | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * 设置窗口的相关属性 | ||
106 | + */ | ||
107 | + @SuppressLint("InlinedApi") | ||
108 | + private void setPopupWindow() { | ||
109 | + this.setContentView(mPopView);// 设置View | ||
110 | + this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);// 设置弹出窗口的宽 | ||
111 | + this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);// 设置弹出窗口的高 | ||
112 | + this.setFocusable(true);// 设置弹出窗口可 | ||
113 | + this.setAnimationStyle(R.style.AnimTopMiddle);// 设置动画 | ||
114 | + this.setBackgroundDrawable(new ColorDrawable(0x00000000));// 设置背景透明 | ||
115 | + this.setOutsideTouchable(true); | ||
116 | +// this.setOnDismissListener(new OnDismissListener() { //退出popupwidon时显示父控件原来的颜色 | ||
117 | +// @Override | ||
118 | +// public void onDismiss() { | ||
119 | +// WindowManager.LayoutParams lp = getWindow().getAttributes(); | ||
120 | +// lp.alpha = 1.0f; | ||
121 | +// getWindow().setAttributes(lp); | ||
122 | +// } | ||
123 | +// }); | ||
124 | +// mPopView.setOnTouchListener(new View.OnTouchListener() {// 如果触摸位置在窗口外面则销毁 | ||
125 | +// @Override | ||
126 | +// public boolean onTouch(View v, MotionEvent event) { | ||
127 | +// int height = mPopView.findViewById(R.id.id_pop_layout).getTop(); | ||
128 | +// int y = (int) event.getY(); | ||
129 | +// if (event.getAction() == MotionEvent.ACTION_UP) { | ||
130 | +// if (y < height) { | ||
131 | +// dismiss(); | ||
132 | +// } | ||
133 | +// } | ||
134 | +// return true; | ||
135 | +// } | ||
136 | +// }); | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public void onClick(View v) { | ||
141 | + switch (v.getId()) { | ||
142 | + case R.id.play: | ||
143 | + if (!mediaPlayer.isPlaying()) {//没播放 | ||
144 | + mediaPlayer.start();//开始播放 | ||
145 | + mediaPlayer.seekTo(currentPosition); | ||
146 | + //监听播放时回调函数 | ||
147 | + timer = new Timer(); | ||
148 | + timer.schedule(new TimerTask() { | ||
149 | + | ||
150 | + Runnable updateUI = new Runnable() { | ||
151 | + @Override | ||
152 | + public void run() { | ||
153 | + musicCur.setText(format.format(mediaPlayer.getCurrentPosition()) + ""); | ||
154 | + } | ||
155 | + }; | ||
156 | + | ||
157 | + @Override | ||
158 | + public void run() { | ||
159 | + if (!isSeekBarChanging) { | ||
160 | + seekBar.setProgress(mediaPlayer.getCurrentPosition()); | ||
161 | + ((Activity) mContext).runOnUiThread(updateUI); | ||
162 | + } | ||
163 | + } | ||
164 | + }, 0, 50); | ||
165 | + } else { | ||
166 | + currentPosition = seekBar.getProgress(); | ||
167 | + mediaPlayer.pause();//暂停播放 | ||
168 | + } | ||
169 | + break; | ||
170 | + case R.id.tv_downloud: | ||
171 | + break; | ||
172 | + case R.id.id_pop_layout: | ||
173 | + currentPosition = seekBar.getProgress(); | ||
174 | + mediaPlayer.pause();//暂停播放 | ||
175 | + dismiss(); | ||
176 | + break; | ||
177 | + } | ||
178 | + | ||
179 | + } | ||
180 | + | ||
181 | + /** | ||
182 | + * 初始化播放器 | ||
183 | + * | ||
184 | + * @param url | ||
185 | + * @param title | ||
186 | + */ | ||
187 | + private void initMediaPlayer(String url, String title) { | ||
188 | + try { | ||
189 | +// mediaPlayer.setDataSource("http://class.ynsdfx.com/uploads/20200410/4958b3dc56895cedffbe20ca86869c4c.wav");//指定音频文件的路径 | ||
190 | + mediaPlayer.setDataSource(url);//指定音频文件的路径 | ||
191 | + mediaPlayer.prepare();//让mediaplayer进入准备状态 | ||
192 | + mediaPlayer.setLooping(true); | ||
193 | + mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | ||
194 | + public void onPrepared(MediaPlayer mp) { | ||
195 | + seekBar.setMax(mediaPlayer.getDuration()); | ||
196 | + musicLength.setText(format.format(mediaPlayer.getDuration()) + ""); | ||
197 | + musicCur.setText("00:00"); | ||
198 | + musicName.setText(title); | ||
199 | + } | ||
200 | + }); | ||
201 | + } catch (Exception e) { | ||
202 | + e.printStackTrace(); | ||
203 | + } | ||
204 | + } | ||
205 | + | ||
206 | + public void destroy() { | ||
207 | + isSeekBarChanging = true; | ||
208 | + if (mediaPlayer != null) { | ||
209 | + mediaPlayer.stop(); | ||
210 | + mediaPlayer.release(); | ||
211 | + mediaPlayer = null; | ||
212 | + } | ||
213 | + if (timer != null) { | ||
214 | + timer.cancel(); | ||
215 | + timer = null; | ||
216 | + } | ||
217 | + } | ||
218 | + | ||
219 | + /*进度条处理*/ | ||
220 | + public class MySeekBar implements SeekBar.OnSeekBarChangeListener { | ||
221 | + | ||
222 | + public void onProgressChanged(SeekBar seekBar, int progress, | ||
223 | + boolean fromUser) { | ||
224 | + } | ||
225 | + | ||
226 | + /*滚动时,应当暂停后台定时器*/ | ||
227 | + public void onStartTrackingTouch(SeekBar seekBar) { | ||
228 | + isSeekBarChanging = true; | ||
229 | + } | ||
230 | + | ||
231 | + /*滑动结束后,重新设置值*/ | ||
232 | + public void onStopTrackingTouch(SeekBar seekBar) { | ||
233 | + isSeekBarChanging = false; | ||
234 | + mediaPlayer.seekTo(seekBar.getProgress()); | ||
235 | + } | ||
236 | + } | ||
237 | +} |
@@ -15,25 +15,6 @@ | @@ -15,25 +15,6 @@ | ||
15 | 15 | ||
16 | <LinearLayout | 16 | <LinearLayout |
17 | android:layout_width="match_parent" | 17 | android:layout_width="match_parent" |
18 | - android:layout_height="@dimen/dp_300" | ||
19 | - android:visibility="gone" | ||
20 | - android:layout_alignParentBottom="true" | ||
21 | - android:orientation="vertical"> | ||
22 | - | ||
23 | - <SeekBar | ||
24 | - android:id="@+id/seekBar1" | ||
25 | - android:layout_width="match_parent" | ||
26 | - android:layout_height="wrap_content" /> | ||
27 | - | ||
28 | - <Button | ||
29 | - android:id="@+id/btn_bofang" | ||
30 | - android:layout_width="wrap_content" | ||
31 | - android:layout_height="wrap_content" | ||
32 | - android:text="播放" /> | ||
33 | - </LinearLayout> | ||
34 | - | ||
35 | - <LinearLayout | ||
36 | - android:layout_width="match_parent" | ||
37 | android:layout_height="@dimen/dp_44" | 18 | android:layout_height="@dimen/dp_44" |
38 | android:gravity="center" | 19 | android:gravity="center" |
39 | android:orientation="horizontal"> | 20 | android:orientation="horizontal"> |
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | -<RelativeLayout | ||
3 | - xmlns:android="http://schemas.android.com/apk/res/android" | ||
4 | - android:layout_margin="20dp" | 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 | + android:id="@+id/id_pop_layout" | ||
5 | android:layout_width="match_parent" | 4 | android:layout_width="match_parent" |
6 | - android:layout_height="match_parent"> | 5 | + android:layout_height="match_parent" |
6 | + android:background="#50000000" | ||
7 | + android:orientation="vertical"> | ||
7 | 8 | ||
8 | <LinearLayout | 9 | <LinearLayout |
9 | - android:orientation="vertical" | ||
10 | - android:layout_marginTop="20dp" | ||
11 | android:layout_width="match_parent" | 10 | android:layout_width="match_parent" |
12 | - android:layout_height="wrap_content"> | 11 | + android:layout_height="match_parent" |
12 | + android:orientation="vertical"> | ||
13 | 13 | ||
14 | - <TextView | ||
15 | - android:id="@+id/music_name" | ||
16 | - android:layout_gravity="center_horizontal" | ||
17 | - android:layout_width="wrap_content" | ||
18 | - android:layout_height="wrap_content"/> | ||
19 | - | ||
20 | - <RelativeLayout | 14 | + <View |
21 | android:layout_width="match_parent" | 15 | android:layout_width="match_parent" |
22 | - android:layout_height="wrap_content"> | 16 | + android:layout_height="0dp" |
17 | + android:layout_weight="1" /> | ||
23 | 18 | ||
24 | - <SeekBar | ||
25 | - android:id="@+id/seekBar" | ||
26 | - android:layout_marginTop="80dp" | ||
27 | - android:layout_width="match_parent" | ||
28 | - android:progressDrawable="@drawable/seekbar_style" | ||
29 | - android:thumb="@drawable/seekbar_thumb" | ||
30 | - android:layout_height="wrap_content"/> | 19 | + <LinearLayout |
20 | + android:layout_width="match_parent" | ||
21 | + android:layout_height="wrap_content" | ||
22 | + android:background="@drawable/shape_solid_10_10_fff" | ||
23 | + android:orientation="vertical" | ||
24 | + android:padding="@dimen/dp_20"> | ||
31 | 25 | ||
32 | <LinearLayout | 26 | <LinearLayout |
33 | - android:layout_below="@id/seekBar" | ||
34 | - android:layout_alignEnd="@id/seekBar" | ||
35 | - android:layout_width="wrap_content" | ||
36 | - android:layout_height="wrap_content"> | ||
37 | - | ||
38 | - <TextView | ||
39 | - android:id="@+id/music_cur" | ||
40 | - android:layout_width="wrap_content" | ||
41 | - android:layout_height="wrap_content"/> | 27 | + android:layout_width="match_parent" |
28 | + android:layout_height="wrap_content" | ||
29 | + android:orientation="horizontal"> | ||
42 | 30 | ||
43 | <TextView | 31 | <TextView |
44 | - android:layout_width="wrap_content" | 32 | + android:id="@+id/music_name" |
33 | + android:layout_width="0dp" | ||
45 | android:layout_height="wrap_content" | 34 | android:layout_height="wrap_content" |
46 | - android:text="/"/> | 35 | + android:layout_gravity="center_horizontal" |
36 | + android:layout_weight="1"/> | ||
47 | 37 | ||
48 | <TextView | 38 | <TextView |
49 | - android:id="@+id/music_length" | 39 | + android:id="@+id/tv_downloud" |
50 | android:layout_width="wrap_content" | 40 | android:layout_width="wrap_content" |
51 | - android:layout_height="wrap_content"/> | 41 | + android:layout_height="wrap_content" |
42 | + android:text="下载到手机" | ||
43 | + android:textColor="#FFAB13" /> | ||
52 | 44 | ||
53 | </LinearLayout> | 45 | </LinearLayout> |
54 | 46 | ||
55 | - </RelativeLayout> | 47 | + <RelativeLayout |
48 | + android:layout_width="match_parent" | ||
49 | + android:layout_height="wrap_content"> | ||
56 | 50 | ||
57 | - </LinearLayout> | 51 | + <SeekBar |
52 | + android:id="@+id/seekBar" | ||
53 | + android:layout_width="match_parent" | ||
54 | + android:layout_height="wrap_content" | ||
55 | + android:layout_marginTop="40dp" | ||
56 | + android:progressDrawable="@drawable/seekbar_style" | ||
57 | + android:thumb="@drawable/seekbar_thumb" /> | ||
58 | 58 | ||
59 | - <LinearLayout | ||
60 | - android:gravity="center" | ||
61 | - android:layout_width="match_parent" | ||
62 | - android:layout_height="match_parent"> | 59 | + <LinearLayout |
60 | + android:layout_width="match_parent" | ||
61 | + android:layout_height="wrap_content" | ||
62 | + android:layout_below="@id/seekBar" | ||
63 | + android:layout_alignEnd="@id/seekBar" | ||
64 | + android:layout_marginTop="@dimen/dp_5"> | ||
63 | 65 | ||
64 | - <ImageButton | ||
65 | - android:id="@+id/play" | ||
66 | - android:src="@mipmap/ic_music_play2x" | ||
67 | - android:background="@null" | ||
68 | - android:layout_width="25dp" | ||
69 | - android:layout_height="25dp"/> | 66 | + <TextView |
67 | + android:id="@+id/music_cur" | ||
68 | + android:layout_width="wrap_content" | ||
69 | + android:layout_height="wrap_content" | ||
70 | + android:text="ddde" /> | ||
70 | 71 | ||
71 | - <ImageButton | ||
72 | - android:id="@+id/pause" | ||
73 | - android:src="@mipmap/ic_sound_recording" | ||
74 | - android:background="@null" | ||
75 | - android:layout_marginLeft="20dp" | ||
76 | - android:layout_width="25dp" | ||
77 | - android:layout_height="25dp"/> | 72 | + <TextView |
73 | + android:layout_width="0dp" | ||
74 | + android:layout_height="wrap_content" | ||
75 | + android:layout_weight="1" /> | ||
78 | 76 | ||
79 | - <ImageButton | ||
80 | - android:id="@+id/stop" | ||
81 | - android:src="@mipmap/ic_sound_recording" | ||
82 | - android:background="@null" | ||
83 | - android:layout_marginLeft="20dp" | ||
84 | - android:layout_width="25dp" | ||
85 | - android:layout_height="25dp"/> | 77 | + <TextView |
78 | + android:id="@+id/music_length" | ||
79 | + android:layout_width="wrap_content" | ||
80 | + android:layout_height="wrap_content" | ||
81 | + android:text="ddd" /> | ||
82 | + | ||
83 | + </LinearLayout> | ||
84 | + | ||
85 | + </RelativeLayout> | ||
86 | + | ||
87 | + <LinearLayout | ||
88 | + android:layout_width="match_parent" | ||
89 | + android:layout_height="match_parent" | ||
90 | + android:gravity="center"> | ||
91 | + | ||
92 | + <ImageView | ||
93 | + android:id="@+id/play" | ||
94 | + android:layout_width="@dimen/dp_72" | ||
95 | + android:layout_height="@dimen/dp_72" | ||
96 | + android:background="@null" | ||
97 | + android:src="@mipmap/ic_music_play2x" /> | ||
98 | + | ||
99 | + <ImageButton | ||
100 | + android:id="@+id/pause" | ||
101 | + android:layout_width="25dp" | ||
102 | + android:layout_height="25dp" | ||
103 | + android:layout_marginLeft="20dp" | ||
104 | + android:visibility="gone" | ||
105 | + android:background="@null" | ||
106 | + android:src="@mipmap/ic_sound_recording" /> | ||
107 | + | ||
108 | + <ImageButton | ||
109 | + android:id="@+id/stop" | ||
110 | + android:layout_width="25dp" | ||
111 | + android:layout_height="25dp" | ||
112 | + android:layout_marginLeft="20dp" | ||
113 | + android:visibility="gone" | ||
114 | + android:background="@null" | ||
115 | + android:src="@mipmap/ic_sound_recording" /> | ||
116 | + | ||
117 | + </LinearLayout> | ||
118 | + </LinearLayout> | ||
86 | 119 | ||
87 | </LinearLayout> | 120 | </LinearLayout> |
88 | 121 | ||
89 | <LinearLayout | 122 | <LinearLayout |
90 | - android:gravity="bottom|right" | ||
91 | - android:orientation="vertical" | ||
92 | android:layout_width="match_parent" | 123 | android:layout_width="match_parent" |
93 | - android:layout_height="match_parent"> | 124 | + android:layout_height="match_parent" |
125 | + android:gravity="bottom|right" | ||
126 | + android:orientation="vertical"> | ||
94 | 127 | ||
95 | <ImageButton | 128 | <ImageButton |
96 | android:id="@+id/volume_plus" | 129 | android:id="@+id/volume_plus" |
97 | - android:src="@android:drawable/ic_input_add" | ||
98 | - android:background="@null" | ||
99 | android:layout_width="wrap_content" | 130 | android:layout_width="wrap_content" |
100 | - android:layout_height="wrap_content"/> | 131 | + android:layout_height="wrap_content" |
132 | + android:background="@null" | ||
133 | + android:src="@android:drawable/ic_input_add" /> | ||
101 | 134 | ||
102 | <ImageButton | 135 | <ImageButton |
103 | android:id="@+id/volume_decrease" | 136 | android:id="@+id/volume_decrease" |
104 | - android:src="@android:drawable/arrow_down_float" | ||
105 | - android:background="@null" | ||
106 | - android:layout_marginTop="20dp" | ||
107 | android:layout_width="wrap_content" | 137 | android:layout_width="wrap_content" |
108 | - android:layout_height="wrap_content"/> | 138 | + android:layout_height="wrap_content" |
139 | + android:layout_marginTop="20dp" | ||
140 | + android:background="@null" | ||
141 | + android:src="@android:drawable/arrow_down_float" /> | ||
109 | 142 | ||
110 | </LinearLayout> | 143 | </LinearLayout> |
111 | 144 | ||
112 | -</RelativeLayout> | ||
145 | +</LinearLayout> |
app/src/main/res/layout/popup_download.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + android:layout_width="match_parent" | ||
4 | + android:layout_height="match_parent" | ||
5 | + android:background="#50000000" | ||
6 | + android:orientation="vertical"> | ||
7 | + | ||
8 | + <LinearLayout | ||
9 | + android:layout_width="match_parent" | ||
10 | + android:layout_height="match_parent" | ||
11 | + android:orientation="vertical"> | ||
12 | + <View android:layout_width="match_parent" | ||
13 | + android:layout_height="0dp" | ||
14 | + android:layout_weight="1"/> | ||
15 | + <LinearLayout | ||
16 | + android:layout_width="match_parent" | ||
17 | + android:layout_height="wrap_content" | ||
18 | + android:background="@drawable/shape_solid_10_10_fff" | ||
19 | + android:orientation="vertical"> | ||
20 | + | ||
21 | + <TextView | ||
22 | + android:id="@+id/tv_download" | ||
23 | + android:layout_width="match_parent" | ||
24 | + android:layout_height="@dimen/dp_50" | ||
25 | + android:gravity="center" | ||
26 | + android:text="下载到手机" | ||
27 | + android:textColor="#06121E" | ||
28 | + android:textSize="@dimen/dp_15"></TextView> | ||
29 | + | ||
30 | + <View | ||
31 | + android:layout_width="wrap_content" | ||
32 | + android:layout_height="1dp" | ||
33 | + android:layout_marginLeft="@dimen/dp_28" | ||
34 | + android:layout_marginRight="@dimen/dp_28" | ||
35 | + android:background="#EBEBEB"></View> | ||
36 | + | ||
37 | + <TextView | ||
38 | + android:id="@+id/tv_zhuanfa" | ||
39 | + android:layout_width="match_parent" | ||
40 | + android:layout_height="@dimen/dp_50" | ||
41 | + android:gravity="center" | ||
42 | + android:text="播放音频" | ||
43 | + android:textColor="#06121E" | ||
44 | + android:textSize="@dimen/dp_15"></TextView> | ||
45 | + | ||
46 | + | ||
47 | + <View | ||
48 | + android:layout_width="wrap_content" | ||
49 | + android:layout_height="3dp" | ||
50 | + android:background="#EBEBEB"></View> | ||
51 | + | ||
52 | + <TextView | ||
53 | + android:id="@+id/tv_cancal" | ||
54 | + android:layout_width="match_parent" | ||
55 | + android:layout_height="@dimen/dp_50" | ||
56 | + android:gravity="center" | ||
57 | + android:text="取消" | ||
58 | + android:textColor="#8C9198" | ||
59 | + android:textSize="@dimen/dp_15"></TextView> | ||
60 | + </LinearLayout> | ||
61 | + | ||
62 | + </LinearLayout> | ||
63 | +</LinearLayout> |
-
请 注册 或 登录 后发表评论