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

 
 
版权声明:本文为博主原创文章,未经博主允许不得转载,转载请标出原文出处。

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的一个播放器,和自己编写的音乐管理程序的更多相关文章

  1. 使用AVPlayer制作一个播放器

    代码地址如下:http://www.demodashi.com/demo/11685.html AVPlayer 是一个强大的视频播放器,可以播放多种格式的视频,缺点是没有控制界面,需要自己去实现. ...

  2. 使用VideoView自定义一个播放器控件

    介绍 最近要使用播放器做一个简单的视频播放功能,开始学习VideoView,在横竖屏切换的时候碰到了点麻烦,不过在查阅资料后总算是解决了.在写VideoView播放视频时候定义控制的代码全写在Actv ...

  3. 使用AVPlayer自定义支持全屏的播放器(五)—Swift重构版本

    前言 很早之前开源了一个简单的视频播放器,由于年久失修,效果惨目忍睹,最近特意花时间对其进行了深度重构.旧版本后期不再维护,新版本使用Swift实现,后续会增加更多功能.不想看文字的请自行下载代码-- ...

  4. 业余写的一个播放器SDK,求点意见

    好久没写博客了 现大致花了半年时间私下写一个音频SDK,想请csdn的达人提点意见,看看还需要增加哪些功能 我对这个的定位如下: 可以在游戏开发中播放音乐,作为一般的音频播放器后端,作为音频编辑器后端 ...

  5. 使用Mediaplay类写一个播放器

    我们知道android本身播放视频的的能力是有限的..先来一个Demo 另附我的一个还未成熟的播放器,下载地址:http://www.eoemarket.com/soft/370334.html,正在 ...

  6. phongap开发中安卓平台上如何调用第三方播放器来播放HLS视频

    前文曾经讲了关于在安卓平台上利用phonegap开发播放HLS的解决方案,其实最好的方案就是自己针对HLS视频开发自己的播放器,但是开发播放器是一个浩大的工程,必须对原生安卓开发非常熟悉,并且对视频播 ...

  7. .net C# 网页播放器 支持多种格式 媒体播放器 播放器 代码

    .avi格式代码片断如下:<object id='video' width='400' height='200' border='0' classid='clsid:CFCDAA03-8BE4- ...

  8. 【C++】从零开始,只使用FFmpeg,Win32 API,实现一个播放器(一)

    前言 起初只是想做一个直接读取视频文件然后播放字符动画的程序.我的设想很简单,只要有现成的库,帮我把视频文件解析成一帧一帧的原始画面信息,那么我只需要读取里面的每一个像素的RGB数值,计算出亮度,然后 ...

  9. 一个开源音乐播放器,低仿QQ音乐!

    有暇,弄了个音乐播放器,页面效果整体上参考了QQ音乐,相关API使用了易源数据提供的相关接口(https://www.showapi.com/api/lookPoint/213),在此表示感谢.先来看 ...

随机推荐

  1. CSS学习(一)---使用CSS的四种方式

      1. 行内样式 例: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  2. javascript 数字字母组合的随机数

    Math.random()方法用于生成,结果为0-1间的一个伪随机数(包括0,不包括1) ,通常的办法是结合parseInt().Math.floor() 或者 Math.ceil()进行四舍五入处理 ...

  3. mongodb学习一

    Windows 平台安装 MongoDB MongoDB 下载 MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制 ...

  4. 【css3】旋转倒计时

    很多答题的H5界面上有旋转倒计时的效果,一个不断旋转减少的动画,类似于下图的这样. 今天研究了下,可以通过border旋转得到.一般我们可以通过border得到一个四段圆. See the Pen c ...

  5. Java并发系列[5]----ReentrantLock源码分析

    在Java5.0之前,协调对共享对象的访问可以使用的机制只有synchronized和volatile.我们知道synchronized关键字实现了内置锁,而volatile关键字保证了多线程的内存可 ...

  6. 浅学vue

    因之前项目接触了vue,从此我被迷住,简洁而不失优雅,小巧而不乏大匠. 首先我们要了解vue,什么是vue,正如官网所说:Vue.js 是一套构建用户界面的渐进式框架,Vue 的核心库只关注视图层.V ...

  7. javascript Map和Set

    Map和Set JavaScript的默认对象表示方式{}可以视为其他语言中的Map或Dictionary的数据结构,即一组键值对. 但是JavaScript的对象有个小问题,就是键必须是字符串.但实 ...

  8. Flag

    之前一直怕别人知道你在干什么,其实根本没人在乎你在干什么.做好你自己不就行了,现在这里将成为你的记录生活与学习的地方,尽管目前就你自己,但是你要相信,会有千万人和你在一起,大胆的往前走吧.--- 致自 ...

  9. Java采用内部构造器Builder模式进行对类进行构建

    好处: 能保证重叠构造器模式的安全性: 能保证JAVABeans模式的可读性: package cn.lonecloud.builder; /** * 使用内部类构建器来对这个类进行构造 * @Tit ...

  10. Sublime Text编辑远程Linux服务器上的文件

    sublime有个叫sftp的插件,可以通过它直接打开远程机器上的文件进行编辑,并在保存后直接同步到远程linux服务器上. 用Package Control安装插件 按下Ctrl+Shift+P调出 ...