让安卓app支持swf的一个播放器,和自己编写的音乐管理程序
jcenter方式导入
- 在需要用到这个库的module中的build.gradle中的dependencies中加入
dependencies { compile 'com.yhd.hdswfplayer:hdswfplayer:1.0.0'}
Module方式导入
- 下载整个工程,将hdmediaplayer拷贝到工程根目录,settings.gradle中加入
include ':hdswfplayer'
- 1
- 在需要用到这个库的module中的build.gradle中的dependencies中加入
dependencies { compile project(':hdswfplayer')}
如何使用
本类支持播放.swf文件、.html文件(.html可以包裹.swf文件并实现与android的交互)。
在demo中提供.html文件模板实例,如果需要js与android数据交互,请移步demo参考。
HDSwfPlayerHelper
- 初始化
private void initSwf() { //工程assets目录下swf文件对应的html文件路径,如果直接传入swf文件的路径也可以播放,但是不能与js交互 String assetsPath="file:///android_asset/main.html"; SwfPlayerHelper.getInstance(getApplicationContext()) .setJSCallClassName("jsCallClassName")//设置js调用的类名 .setJSCallMethodName("jsCallMethodName")//设置js调用的方法名 .setWebView(webView)//设置flash播放的载体.setSwfPlayerCallBack(new SwfPlayerHelper.SwfPlayerCallBack() {//设置播放过程的回调 @Override public voidonCallBack(SwfPlayerHelper.CallBackState state, final Object... args) { Log.v(TAG, state.toString()); //收到js调用方法发来的参数字符串信息 if(state== SwfPlayerHelper.CallBackState.JS_CALL_ANDROID_METHOD_WITH_PARAM){ runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(),(String)args[0],Toast.LENGTH_LONG).show(); } }); } } }) .playSwf(assetsPath);//传入绝对路径、带file://的绝对路径、url都行}
- 为了让退出播放或者在播放时用户转到其它页面后flash不再播放,应该重写用于播放的Activity的onPause和onResume方法,并分别调用webview的隐藏方法”onPause”和”onResume
@Overrideprotected void onResume() { super.onResume(); SwfPlayerHelper.getInstance(getApplicationContext()).onResume();}@Overrideprotected void onPause() {super.onPause(); SwfPlayerHelper.getInstance(getApplicationContext()).onPause();}
//WebView调用js的基本格式为:webView.loadUrl(“javascript:methodName(parameterValues)”)SwfPlayerHelper.getInstance(getApplicationContext()).androidCallJsMethod("jsMethodString");SwfPlayerHelper.getInstance(getApplicationContext()).androidCallJSMethodWithReturn("jsMethodString");
关于我
欢迎 Star Fork交流地址:尹海德(123302687@qq.com)
License
Copyright 2017 yinhaideLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

Github传送门https://github.com/yinhaide/HDSwfPlayer
- 本文已收录于以下专栏:
- Android开源之路
package totoo.player;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import totoo.player.network.Ex_adp;
import totoo.player.network.downLoad_item_Info;
import totoo.touhouplayer.R;
import totoo.ui.ItemListActivity;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.widget.DrawerLayout;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class Activity_Main extends Activity implements OnSeekBarChangeListener,
OnClickListener {
static ListView lv_song, lv_like, listView;
ImageView btn_go, btn_next, btn_back;
SimpleAdapter simpleAdapter_Likes, simpleAdapter_Songs;
static RelativeLayout main_RelativeLayout;
static LinearLayout Main_c_LinearLayout;
// static DrawerLayout main_drawerLayout;
List<Map<String, String>> list_song = new ArrayList<Map<String, String>>();
List<Map<String, String>> list_like = new ArrayList<Map<String, String>>();
// GestureDetector gestureDetector;
public static SeekBar Main_seekbar;
static Context mContext;
public static boolean SongSinglePlay = true;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (null == Service_Play.startMusicSer)
Service_Play.startMusicSer = startService(new Intent(
Constants.PlayerServiceName));
regConView();
Uri data = getIntent().getData();
if (data != null) {
// Toast.makeText(this, data.toString(), Toast.LENGTH_SHORT).show();
Service_Play.Action_ChangeSong(data);
}
}
protected void onRestart() {
if (null == Service_Play.startMusicSer)
Service_Play.startMusicSer = startService(new Intent(
Constants.PlayerServiceName));
Uri data = getIntent().getData();
if (data != null) {
// Toast.makeText(this, data.toString(), 0).show();
Service_Play.Action_ChangeSong(data);
}
macthBG();
super.onRestart();
}
protected void onDestroy() {
// VH.killTask(this);
super.onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
bg_Handler.sendEmptyMessage(0);
}
@SuppressLint("NewApi")
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (touchAble)
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
try {
if (main_RelativeLayout.getX() > 75) {
main_RelativeLayout.setX(0);
Main_c_LinearLayout.setX(-200);
} else {
main_RelativeLayout.setX(150);
Main_c_LinearLayout.setX(0);
}
} catch (Exception e) {
}
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
// true;
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.Main_act_go_imageView:
sendBroadcast(new Intent(Constants.BROADCAST_NAME).putExtra(
Constants.TAG_rspID, Constants.BTN_Go));
// Service_Play.play();
break;
case R.id.Main_act_next_ImageView02:
ChangeMusicPlay(Constants.Play_id = Constants.Play_id + 1,
Constants.musicBeans_all);
break;
case R.id.Main_act_back_ImageView01:
ChangeMusicPlay(Constants.Play_id = Constants.Play_id - 1,
Constants.musicBeans_all);
break;
default:
break;
}
}
// class MusicBroadCastReceiver extends BroadcastReceiver {
//
// public void onReceive(Context arg0, Intent intent) {
// int id = intent.getIntExtra(VH.TAG_rspID, -1);
// switch (id) {
// case VH.changedProgress:
// int progress = intent.getIntExtra(
// VH.TAG_changedProgress, 0);
// int max = intent
// .getIntExtra(VH.TAG_changedLimit, 100);
// Main_seekbar.setMax(max);
// Main_seekbar.setProgress(progress);
// default:
// }
// }
// }
static void ChangeMusicPlay(int id, List<MusicBean> list) {
try {
MusicBean hashMap = list.get(id);
String stringname = hashMap.getMusicPath();
Service_Play.Action_ChangeSong(new Intent().putExtra("name",
stringname));
} catch (Exception e) {
}
}
// public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.playing_list, menu);
// menu.add("放大");
// menu.add("分享");
// menu.add("刪除");
// main_drawerLayout.openDrawer(Gravity.LEFT);
// return true;
// }
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
// case 0:
// Intent intent = new Intent(this, Activity_PlayingList.class);
// startActivityForResult(intent, Constants.MusicR_code);
// break;
// case 1:
//
// break;
// case 2:
//
// break;
//
// default:
// break;
// }
// return super.onOptionsItemSelected(item);
// }
class Kill_BroadCastReceiver extends BroadcastReceiver {
public void onReceive(Context arg0, Intent intent) {
finish();
}
}
public void onStopTrackingTouch(SeekBar seekBar) {
Intent intent = new Intent(Constants.BROADCAST_NAME);
intent.putExtra(Constants.TAG_rspID, Constants.changedProgress);
int i = seekBar.getProgress();
intent.putExtra(Constants.TAG_changedProgress, i);
sendBroadcast(intent);
}
// 空事件_________________________________________________________________________________________________
//
void tz(String str) {//
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();//
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
}
// final int touchXLimit = 400;
float beforeNum = 0;
int sinceNum;
float fillingNum;
boolean clickFlag = false;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onTouchEvent(MotionEvent event) {//
// tz("你摸了我一下");
try {
Thread.sleep(40);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (touchAble)
try {
fillingNum = event.getX();
main_RelativeLayout.setX((int) fillingNum - beforeNum);
// Main_c_LinearLayout.setX(fillingNum - 120 - beforeNum);
// listView.setX((int) (fillingNum ));
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
beforeNum = event.getX();
Main_c_LinearLayout.setX(0);
break;
case MotionEvent.ACTION_UP:
// sinceNum = (int) event.getX();
if (main_RelativeLayout.getX() < 150) {
main_RelativeLayout.setX(0);
Main_c_LinearLayout.setX(-200);
} else {
main_RelativeLayout.setX(150);
Main_c_LinearLayout.setX(0);
}
// if (clickFlag) {
// clickFlag = false;
// startActivity(new Intent(this,
// Activity_PlayingList.class));
// this.overridePendingTransition(R.anim.right_in,
// R.anim.left_out);
// }
// if (beforeNum > touchXLimit) {
// clickFlag = true;
if (beforeNum - event.getX() > 350) {
startActivity(new Intent(this,
Activity_PlayingList.class));
this.overridePendingTransition(R.anim.right_in,
R.anim.left_out);
} else if (event.getX() - beforeNum > 350) {
this.overridePendingTransition(
android.R.anim.slide_in_left,
android.R.anim.slide_out_right);
finish();
}
break;
// case KeyEvent.KEYCODE_MENU:
// // if (main_drawerLayout.isDrawerOpen(Gravity.LEFT))
// // main_drawerLayout.closeDrawers();
// // else
// // main_drawerLayout.openDrawer(Gravity.LEFT);
//
}
} catch (Exception e) {
}
else {
bflag++;
if (bflag>15) {
macthTouch();
bflag = 0;
}
}
return false;
// gestureDetector.onTouchEvent(event);//
}//
int bflag = 0;
// public boolean onDown(MotionEvent e) {//
// return false;//
// }//
// //
//
// public void onShowPress(MotionEvent e) {//
// //
// }//
//
// public boolean onSingleTapUp(MotionEvent e) {//
// return false;//
// }//
// //
//
// public boolean onScroll(MotionEvent e1, MotionEvent e2, float
// distanceX,//
// float distanceY) {//
// return false;
// }//
// //
//
// public void onLongPress(MotionEvent e) {//
// //
// }//
// //
// 空事件结束_________________________________________________________________________________________________
//
// public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
// float velocityY) {
//
// // if (event.getX() - beforeX > 50) {
// // if (main_drawerLayout.isDrawerVisible(Gravity.RIGHT)) {
// // main_drawerLayout.closeDrawers();
// // }
// // } else if (beforeX - event.getX() > 50) {
// // try {
// // main_drawerLayout.openDrawer(Gravity.RIGHT);
// // } catch (Exception e) {
// // }
// // }
// // // else {
// // // startActivity(new Intent(Activity_Main.this,
// // // Activity_PlayingList.class));
// // // Activity_Main.this.overridePendingTransition(
// // // R.anim.right_in, R.anim.left_out);
// // // }
// // }
// // if (event.getX() - beforeX > 300) {
// // // if (main_drawerLayout.isDrawerVisible(Gravity.LEFT)) {
// // // main_drawerLayout.closeDrawers();
// // // } else {
// // Activity_Main.this.overridePendingTransition(
// // android.R.anim.slide_in_left,
// // android.R.anim.slide_out_right);
// // finish();}}
// return true;
// }
void regConView() {
// MusicBroadCastReceiver MusicService_receiver; = new
// MusicBroadCastReceiver();
// registerReceiver(MusicService_receiver,
// new IntentFilter(VH.BROADCAST_NAME));
Kill_BroadCastReceiver killService_receiver = new Kill_BroadCastReceiver();
registerReceiver(killService_receiver, new IntentFilter(
Constants.kill_BROADCAST_NAME));
// gestureDetector = new GestureDetector(this, this);
mContext = Activity_Main.this;
if (null == Activity_Splash.thread1) {
Activity_Splash.mContext = Activity_Main.this;
Activity_Splash.contentResolver = Activity_Main.this
.getContentResolver();
Activity_Splash.thread1 = Activity_Splash.callOneThread();
Activity_Splash.thread2 = Activity_Splash.callThreadTwo();
}
if (null == Service_Play.startMusicSer)
Service_Play.startMusicSer = startService(new Intent(
Constants.PlayerServiceName));
//
listView = (ListView) findViewById(R.id.Main_c_ListView);
// listViewLinearLayout = (LinearLayout)
// findViewById(R.id.Main_controler_LinearLayout);
// listView.setLeft(-200);
lv_song = (ListView) findViewById(R.id.listViewSongs);
Constants.createListSongs(lv_song);
lv_like = (ListView) findViewById(R.id.listViewlikes);
Constants.createListLikes(lv_like);
Main_seekbar = (SeekBar) findViewById(R.id.Main_seekBar);
Main_seekbar.setOnSeekBarChangeListener(this);
Main_seekbar.setMax(Constants.current_play_max);
btn_go = (ImageView) findViewById(R.id.Main_act_go_imageView);
btn_back = (ImageView) findViewById(R.id.Main_act_back_ImageView01);
btn_next = (ImageView) findViewById(R.id.Main_act_next_ImageView02);
btn_go.setOnClickListener(this);
btn_next.setOnClickListener(this);
btn_back.setOnClickListener(this);
// main_drawerLayout = (DrawerLayout)
// findViewById(R.id.Main_controler_DrawerLayout);
// main_drawerLayout.setOnTouchListener(new OnTouchListener() {
// @SuppressLint("NewApi")
// public boolean onTouch(View v, MotionEvent event) {
//
// fillingNum = event.getX();
// // main_RelativeLayout.setLeft((int) fillingNum);
// // listView.setLeft((int) (fillingNum - 120));
//
// switch (event.getAction()) {
// case MotionEvent.ACTION_DOWN:
// if (fillingNum > 100) {
// if (main_drawerLayout.isDrawerOpen(Gravity.LEFT))
// main_drawerLayout.closeDrawers();
// else
// main_drawerLayout.openDrawer(Gravity.LEFT);
// if (main_RelativeLayout.getLeft() < 100)
// if (!main_drawerLayout.isDrawerOpen(Gravity.LEFT))
// main_RelativeLayout.setLeft(150);
// else
// main_RelativeLayout.setLeft(0);
// }
// break;
// case MotionEvent.ACTION_UP:
// // sinceNum = (int) event.getX();
//
// // listView.setLeft(0);
//
// }
// return false;
// }
// });
// cl(lv_like, simpleAdapter_Likes, R.layout.li_likes, list_like);
// cl(lv_song, simpleAdapter_Songs, R.layout.li_songs, list_song);
Activity_Main.LayoutSystem_Handler.sendEmptyMessage(0);
main_RelativeLayout = (RelativeLayout) findViewById(R.id.main_RelativeLayout);
Main_c_LinearLayout = (LinearLayout) findViewById(R.id.Main_c_LinearLayout);
// new Thread(new Runnable() {
// public void run() {
macthBG();
// }
// }).start();
// macthTouch();
}
void macthTouch() {
// TODO Auto-generated method stub
// preferences = getSharedPreferences("boy", Context.MODE_PRIVATE);
//
// editor = preferences.edit();
// if (-1 == preferences.getInt("a", -1) || !touchAble) {
builder = new Builder(this);
builder.setTitle("您正在使用的是2.2以上系统吗?");
builder.setPositiveButton("打开预览模式",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//
// editor.putInt("a", defaultNum);
// editor.commit();// 提交数据保存
touchAble = true;
}
});
builder.setNegativeButton("兼容",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
// editor.putInt("a", 0);
// editor.commit();// 提交数据保存
touchAble = false;
}
});
builder.show();
}
// }
Builder builder;
boolean touchAble = false;
SharedPreferences preferences;
Editor editor;
int defaultNum = 1;
static File bg_file;
static Handler bg_Handler = new Handler() {
public void handleMessage(android.os.Message msg) {
bg_file = new File(Environment.getExternalStorageDirectory(),
"/music/bg.jpg");
try {
if (null == Constants.BG_img) {
Constants.BG_img = ((BitmapDrawable) (mContext
.getResources().getDrawable(R.drawable.bg)));
}
main_RelativeLayout.setBackgroundDrawable(Constants.BG_img);
if (bg_file.exists())
Constants.BG_img = new BitmapDrawable(
BitmapFactory.decodeFile((bg_file.getPath())));
} catch (Exception e) {
}
}
};
static ArrayAdapter<String> List_arrayAdapter;
static Handler LayoutSystem_Handler = new Handler() {
public void handleMessage(android.os.Message msg) {
List_arrayAdapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_list_item_1);
List_arrayAdapter.add("「更换・背景」");// 0
List_arrayAdapter.add("「单曲・循环」");
List_arrayAdapter.add("「收藏・歌单」");
List_arrayAdapter.add("「填词・图片」");
List_arrayAdapter.add("「在线・资源」");
List_arrayAdapter.add("「网络・传输」");// 5
List_arrayAdapter.add("「设置・铃声」");
List_arrayAdapter.add("「退出」");
List_arrayAdapter.add("");
List_arrayAdapter.add("版本:1.8.0");
List_arrayAdapter.add("");
List_arrayAdapter.add("");
List_arrayAdapter.add("");
List_arrayAdapter.add("");
List_arrayAdapter.add("");
List_arrayAdapter.add("");
listView.setAdapter(List_arrayAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
Builder builder;
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 5:
Intent intent4 = new Intent(Activity_Main.mContext,
ItemListActivity.class);
mContext.startActivity(intent4);
break;
case 4:
try {
builder = new Builder(Activity_Main.mContext);
View view2 = LayoutInflater.from(mContext).inflate(
R.layout.online_get, null);
// builder.setMessage("敬请期待");
ExpandableListView findViewById = (ExpandableListView) view2
.findViewById(R.id.online_get_expandableListView1);
List<downLoad_item_Info> mListKind = new ArrayList<downLoad_item_Info>();
List<List<downLoad_item_Info>> mListAll = new ArrayList<List<downLoad_item_Info>>();
mListKind.add(new downLoad_item_Info(" 【"
+ " 幽闭サテライト - " + "】", "", "", ""));
List<downLoad_item_Info> mlist = new ArrayList<downLoad_item_Info>();
mlist.add(new downLoad_item_Info("华鸟风月 ", "", "",
" - senya- "));
mlist.add(new downLoad_item_Info("三千世界 ", "", "",
" - senya- "));
mlist.add(new downLoad_item_Info(" UN 孤独月 ", "",
"", " - senya- "));
mlist.add(new downLoad_item_Info(" 千华缭乱 ", "", "",
" - senya- "));
mlist.add(new downLoad_item_Info(" カフカ群青へ ", "",
"", " - senya- "));
mListAll.add(mlist);
mListKind
.add(new downLoad_item_Info(" 【"
+ " 舞风 - MAIKAZE" + "】", "",
"", ""));
mlist = new ArrayList<downLoad_item_Info>();
mlist.add(new downLoad_item_Info(" そこに在るもの ", "",
"", " - TOKINE - "));
mlist.add(new downLoad_item_Info(" 愿いを呼ぶ季节 ", "",
"", " - TOKINE - "));
mlist.add(new downLoad_item_Info(" Memory ", "",
"", " - 朝木ゆう - "));
mListAll.add(mlist);
Ex_adp adapter = new Ex_adp(mListKind, mListAll,
mContext);
findViewById.setAdapter(adapter);
builder.setView(view2);
builder.setNegativeButton("终了",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
}
});
builder.show();
} catch (Exception e) {
Toast.makeText(mContext, "阿勒,这个界面奔溃了",
Toast.LENGTH_SHORT).show();
}
break;
case 3:
Intent intent3 = new Intent(Activity_Main.mContext,
Activity_PlayingList.class);
intent3.putExtra("num", 2);
Activity_Main.mContext.startActivity(intent3);
break;
case 2:
Intent intent2 = new Intent(Activity_Main.mContext,
Activity_PlayingList.class);
intent2.putExtra("num", 0);
Activity_Main.mContext.startActivity(intent2);
break;
case 6:
builder = new Builder(Activity_Main.mContext);
//
// builder.setView(LayoutInflater.from(mContext).inflate(
// R.layout.ad_view, null));
builder.setMessage("这个页面,呵其实真的是懒得做");
builder.setNegativeButton("终了",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
builder.show();
break;
case 9:
builder = new Builder(Activity_Main.mContext);
builder.setTitle("1.8重磅打造");
builder.setMessage("好音质,无需隐藏");
builder.setNegativeButton("看过了",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
builder.show();
break;
case 0:
Intent intent = new Intent(Activity_Main.mContext,
Activity_change_bg.class);
((Activity_Main) (Activity_Main.mContext))
.startActivityForResult(intent, 0);
break;
case 1:
// builder = new Builder(Activity_Main.mContext);
//
// builder.setMessage("这个还没有做完呢");
// builder.setNegativeButton("终了",
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog,
// int which) {
// }
// });
// builder.show();
String stringTip = "";
if (SongSinglePlay) {
SongSinglePlay = false;
stringTip = "现在将以单曲循环";
} else {
SongSinglePlay = true;
stringTip = "单曲播放";
}
Toast.makeText(Activity_Main.mContext, stringTip,
Toast.LENGTH_SHORT).show();
break;
case 7:
Constants.selfKillFlag = true;
Constants.killTask(Service_Play.mContext);
break;
}
}
});
}
};
static Handler toast_Handler = new Handler() {
public void handleMessage(android.os.Message msg) {
String string = (String) msg.obj;
Toast.makeText(Activity_Main.mContext, string, Toast.LENGTH_SHORT)
.show();
}
};
static Handler SDSystem_Handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (lv_like != null)
try {
Constants.createListLikes(lv_like);
} catch (Exception e) {
}
}
};
static Handler SystemFlash_Handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (lv_song != null)
try {
if (null == Constants.musicSystem) {
Constants.musicSystem = new ArrayList<Map<String, String>>();
Map<String, String> item = new HashMap<String, String>();
item.put("name", "三千世界鸦杀尽");
item.put("statu", "无名");
item.put("id", "2MB");
Constants.musicBeans_all.add(new MusicBean("三千世界鸦杀尽",
""));
Constants.musicSystem.add(item);
}
Constants.createListSongs(lv_song);
} catch (Exception e) {
}
}
};
private void macthBG() {
// TODO Auto-generated method stub
try {
File file = new File(Constants.SD_path + "/Music/bg.jpg");
if (file.exists()) {
Bitmap decodeFile = BitmapFactory.decodeFile(Constants.SD_path
+ "/music/bg.jpg");
Constants.BG_img = new BitmapDrawable(decodeFile);
} else {
Constants.BG_img = null;
}
} catch (Exception e) {
Constants.BG_img = null;
}
bg_Handler.sendEmptyMessage(0);
}
}
// void cl(ListView listView, SimpleAdapter sa, int ItemLayout_ID,
// List<Map<String, String>> list) {
//
// for (int i = 0; i < 3; i++) {
// HashMap<String, String> item = new HashMap<String, String>();
// item.put("id", "bilibili" + i);
// item.put("name", "bilibili" + i);
// item.put("statu", "bilibili" + i);
// list.add(item);
// }
// sa = new SimpleAdapter(this, list, ItemLayout_ID, new String[] { "id",
// "name", "statu" }, new int[] { R.id.id, R.id.name, R.id.statu });
// listView.setAdapter(sa);
// }
class MusicManager {
public static final String[] MUISC_ATTRS = new String[] {
// 歌曲名
MediaStore.Audio.Media.DISPLAY_NAME,
// 歌手名
MediaStore.Audio.Media.ARTIST,
// 歌曲大小
MediaStore.Audio.Media.SIZE,
// 歌曲时间__________________________________________________________________________
MediaStore.Audio.Media.DURATION,
// 专辑名
MediaStore.Audio.Media.ALBUM,
// 歌曲ID
MediaStore.Audio.Media._ID,
// 歌曲路径
MediaStore.Audio.Media.DATA };
public List<Map<String, String>> getSystemMuisc(ContentResolver cr) {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
// 查询所有音乐信息
Map<String, String> item;
MusicBean musicBean;
Cursor c = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
MUISC_ATTRS, null, null, null);
String name;
String song;
int size;
// 遍历获取数据信息
while (c.moveToNext()) {
item = new HashMap<String, String>();
musicBean = new MusicBean();
musicBean.setMusicSize(size = c.getInt(2));
musicBean.setMusicSinger(name = c.getString(1));
musicBean.setMusicPath(c.getString(6));
musicBean.setMusicName(c.getString(0));
song = c.getString(0);
if (song.endsWith(".mp3") || song.endsWith(".ogg")
|| song.endsWith(".acc") || song.endsWith(".wav")
|| song.endsWith(".f4v") || song.endsWith(".ape")
|| song.endsWith(".flac"))
if (size > 1000000)
if (name != null) {
item.put("name", song);
item.put("statu", name);
item.put("id", (int) (size / 1024 / 1024) + "MB");
Constants.musicBeans_all.add(musicBean);
list.add(item);
}
}
if (list.isEmpty()) {
item = new HashMap<String, String>();
item.put("name", "三千世界鸦杀尽");
item.put("statu", "无名");
item.put("id", "2MB");
Constants.musicBeans_all.add(new MusicBean("三千世界鸦杀尽", ""));
list.add(item);
}
return list;
}
public List<Map<String, String>> getSystemSD() {
ArrayList<Map<String, String>> arrayList = new ArrayList<Map<String, String>>();
Constants.playingBeans = new ArrayList<MusicBean>();
// 查询所有sd信息
Map<String, String> item;
MusicBean musicBean;
File file = Environment.getExternalStorageDirectory();
File[] node = file.listFiles();
String song;
String name;
long size;
for (File child : node) {
song = child.getAbsolutePath();
size = child.length();
if (song.endsWith(".mp3") || song.endsWith(".ogg")
|| song.endsWith(".acc") || song.endsWith(".wav")
|| song.endsWith(".f4v") || song.endsWith(".ape")
|| song.endsWith(".flac"))
if (size > 1000000) {
musicBean = new MusicBean();
name = song.substring(song.lastIndexOf("/") + 1,
song.lastIndexOf("."));
musicBean.setMusicName(name);
musicBean.setMusicPath(song);
musicBean.setMusicSize((int) size);
Constants.playingBeans.add(musicBean);
item = new HashMap<String, String>();
item.put("name", name);
item.put("id", (int) (size / 1024 / 1024) + "MB");
arrayList.add(item);
}
}
return arrayList;
}
}
class MusicBean {
private int _id;
private String musicName;
private String musicSinger;
private int musicTime;
private String musicAlbum;
private int musicSize;
private String musicPath;
private String sortLetter;
public MusicBean() {
}
public MusicBean(String name, String path) {
musicName = name;
musicPath = path;
}
public String getSortLetter() {
return sortLetter;
}
public void setSortLetter(String sortLetter) {
this.sortLetter = sortLetter;
}
public int get_id() {
return _id;
}
public void set_id(int _id) {
this._id = _id;
}
public String getMusicName() {
return musicName;
}
public void setMusicName(String musicName) {
this.musicName = musicName;
}
public String getMusicSinger() {
return musicSinger;
}
public void setMusicSinger(String musicSinger) {
this.musicSinger = musicSinger;
}
public int getMusicTime() {
return musicTime;
}
public void setMusicTime(int musicTime) {
this.musicTime = musicTime;
}
public String getMusicAlbum() {
return musicAlbum;
}
public void setMusicAlbum(String musicAlbum) {
this.musicAlbum = musicAlbum;
}
public int getMusicSize() {
return musicSize;
}
public void setMusicSize(int musicSize) {
this.musicSize = musicSize;
}
public String getMusicPath() {
return musicPath;
}
public void setMusicPath(String musicPath) {
this.musicPath = musicPath;
}
}
// class MusicExpandData {
// List<String> groupListData;
// List<List<MusicBean>> childListData;
//
// public List<String> getGroupListData() {
// return groupListData;
// }
//
// public void setGroupListData(List<String> groupListData) {
// this.groupListData = groupListData;
// }
//
// public List<List<MusicBean>> getChildListData() {
// return childListData;
// }
//
// public void setChildListData(List<List<MusicBean>> childListData) {
// this.childListData = childListData;
// }
// }
// public MusicExpandData getSystemMusicForExpand(ContentResolver cr) {
// MusicExpandData med = new MusicExpandData();
//
// List<MusicBean> list = getSystemMuisc(cr);
//
// List<String> groupList = new ArrayList<String>();
// List<List<MusicBean>> chirdList = new ArrayList<List<MusicBean>>();
// int k = 0;// 用于计算字母的下标
//
// groupList.add("A");
// chirdList.add(new ArrayList<MusicBean>());
//
// for (int i = 0; i < list.size(); i++) {
// MusicBean mb = list.get(i);
// String sortLetter = mb.getSortLetter();
// for (int j = k; j < Letters.length; j++) {
// if (sortLetter.equals(Letters[j])) {
// // 有相等的时候
// List<MusicBean> _list = chirdList.get(j);
// _list.add(mb);
// break;
// } else {// 将下标移动到下一位
//
// k++;
// if (k == Letters.length)
// break;
// groupList.add(Letters[j + 1]);
// chirdList.add(new ArrayList<MusicBean>());
// }
// }
// }
// // 遍历数组去掉空的数组
// for (int i = 0; i < groupList.size(); i++) {
// if (chirdList.get(i).size() < 1) {
// groupList.remove(i);
// chirdList.remove(i);
// i--;
// }
// }
// med.setChildListData(chirdList);
// med.setGroupListData(groupList);
// return med;
// }

让安卓app支持swf的一个播放器,和自己编写的音乐管理程序的更多相关文章
- 使用AVPlayer制作一个播放器
代码地址如下:http://www.demodashi.com/demo/11685.html AVPlayer 是一个强大的视频播放器,可以播放多种格式的视频,缺点是没有控制界面,需要自己去实现. ...
- 使用VideoView自定义一个播放器控件
介绍 最近要使用播放器做一个简单的视频播放功能,开始学习VideoView,在横竖屏切换的时候碰到了点麻烦,不过在查阅资料后总算是解决了.在写VideoView播放视频时候定义控制的代码全写在Actv ...
- 使用AVPlayer自定义支持全屏的播放器(五)—Swift重构版本
前言 很早之前开源了一个简单的视频播放器,由于年久失修,效果惨目忍睹,最近特意花时间对其进行了深度重构.旧版本后期不再维护,新版本使用Swift实现,后续会增加更多功能.不想看文字的请自行下载代码-- ...
- 业余写的一个播放器SDK,求点意见
好久没写博客了 现大致花了半年时间私下写一个音频SDK,想请csdn的达人提点意见,看看还需要增加哪些功能 我对这个的定位如下: 可以在游戏开发中播放音乐,作为一般的音频播放器后端,作为音频编辑器后端 ...
- 使用Mediaplay类写一个播放器
我们知道android本身播放视频的的能力是有限的..先来一个Demo 另附我的一个还未成熟的播放器,下载地址:http://www.eoemarket.com/soft/370334.html,正在 ...
- phongap开发中安卓平台上如何调用第三方播放器来播放HLS视频
前文曾经讲了关于在安卓平台上利用phonegap开发播放HLS的解决方案,其实最好的方案就是自己针对HLS视频开发自己的播放器,但是开发播放器是一个浩大的工程,必须对原生安卓开发非常熟悉,并且对视频播 ...
- .net C# 网页播放器 支持多种格式 媒体播放器 播放器 代码
.avi格式代码片断如下:<object id='video' width='400' height='200' border='0' classid='clsid:CFCDAA03-8BE4- ...
- 【C++】从零开始,只使用FFmpeg,Win32 API,实现一个播放器(一)
前言 起初只是想做一个直接读取视频文件然后播放字符动画的程序.我的设想很简单,只要有现成的库,帮我把视频文件解析成一帧一帧的原始画面信息,那么我只需要读取里面的每一个像素的RGB数值,计算出亮度,然后 ...
- 一个开源音乐播放器,低仿QQ音乐!
有暇,弄了个音乐播放器,页面效果整体上参考了QQ音乐,相关API使用了易源数据提供的相关接口(https://www.showapi.com/api/lookPoint/213),在此表示感谢.先来看 ...
随机推荐
- MySQL学习记录(不断更新)
MySQL设置数据集为UTF8仍无法输入中文的解决办法: 我们的机器默认为gbk,因此可在进入数据库之前,使用以下这条语句将默认编码改为gbk,注意没有单引号,也不要用分号. mysql -uroot ...
- IQKeyboardManager 自动处理键盘事件的第三方库
我们写界面要考虑很多用户体验问题,键盘事件的响应就是比较麻烦的一种.我们需要监听键盘事件,考虑点击背景收起键盘.考虑键盘遮挡输入框问题等等,而且每个界面都要做这么一套.这个库帮我们解决了这个事情. 这 ...
- 插入排序Insertion Sort
插入排序:将一个数据插入到一个已经排好序的有序数据序列中,从而得到一个新的.个数+1的有序数列:插入排序适用于少量数据排序,时间复杂度为O(n^2). 实现思路:1.对于一个无序数组,选取第一个元素, ...
- Android Stutio 3.0 - Gradle sync failed
0.Android Studio 权威教程 (url:http://blog.csdn.net/column/details/zsl-androidstudio.html) 1. 项目老是报错: Gr ...
- Node.js 基础介绍(一)
Node.js 学习笔记一) 简单介绍--名称 Node.js,平时听到有好几种叫法,node .Node.js.nodejs ,但是比较正式的称呼还是"Node.js",由于它是 ...
- 轻松掌握VS Code开发.Net Core及创建Xunit单元测试
前言 本篇文章主要还是介绍使用 VS Code 进行.Net Core开发和常用 CLI命令的使用,至于为啥要用VS Code ,因为它是真的是好看又好用 :) ,哈哈,主要还是为了跨平台开发做准备. ...
- 剑指offer随练
合并两个排序的链表 题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 思路:使用递归的方法,合并头节点,然后对剩下的链表接着合并头节点,直到合并完 ...
- ACdream 1031 Cut
题意:给定一棵树,删除一些边,让整棵树被分成多个节点数为偶数的联通块,且联通块尽量多. 思路:如果出现连通且节点数为偶数的立即删除这个点与它父节点之间的边,尽量删除即可,因为题目说了保证n为偶数,删了 ...
- 吾八哥学Selenium(四):操作下拉框select标签的方法
我们在做web页面自动化测试的时候会经常遇到<select></select>标签的下拉框,那么在Python里如何实现去操作这种控件呢?今天就给大家分享一下这个玩法.为了让大 ...
- Docker系列三:Docker容器管理
Docker容器管理 1. 单一容器管理 1) 容器的启动 $ docker run --name gitlab-redis -d --volume /srv/docker/gitlab/redis: ...