-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #716 from helloSingleDog/master
- Loading branch information
Showing
6 changed files
with
327 additions
and
10 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
.../edu/hzuapps/androidworks/homeworks/net1314080903219/Net1314080903219CreateMusicList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903219; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.app.Service; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import static android.support.v4.app.ActivityCompat.startActivityForResult; | ||
|
||
public class Net1314080903219CreateMusicList extends Service { | ||
private static final int FILE_SELECT_CODE =5 ; | ||
// private String listName; | ||
Net1314080903219FileStoreReader f; | ||
// final EditText inputServer = new EditText(this); | ||
public Net1314080903219CreateMusicList() { | ||
|
||
|
||
|
||
} | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
// TODO: Return the communication channel to the service. | ||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
public int onStartCommand(Intent intent, int flags, int startId){ | ||
|
||
f=new Net1314080903219FileStoreReader(intent.getStringExtra("listName")); | ||
String[] path=intent.getStringExtra("songPath").split("/"); | ||
int l=path.length; | ||
f.store(path[l-1]+":"+intent.getStringExtra("songPath")); | ||
f.close(); | ||
return START_STICKY; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
.../edu/hzuapps/androidworks/homeworks/net1314080903219/Net1314080903219FileStoreReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903219; | ||
|
||
import android.os.Environment; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Created by j1 on 2016/5/6. | ||
*/ | ||
public class Net1314080903219FileStoreReader { | ||
private File object=null; | ||
private FileInputStream fin=null; | ||
private FileOutputStream fout=null; | ||
private int fileLength=0; | ||
public Net1314080903219FileStoreReader(String name){ | ||
object=new File("/storage/sdcard1/Music/"+name+".txt"); | ||
System.out.println(object.getPath()); | ||
if(object.exists()){ | ||
try { | ||
fin=new FileInputStream(object); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
return ; | ||
} | ||
} | ||
|
||
try { | ||
fout=new FileOutputStream(object); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public boolean close(){ | ||
try { | ||
if (fin!=null) { | ||
fin.close(); | ||
} | ||
if(fout!=null){ | ||
fin.close(); | ||
} | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public int store(String data){ | ||
if(fout==null){ | ||
return -1; | ||
} | ||
byte[] by=data.getBytes(); | ||
try { | ||
fout.write(by); | ||
fout.flush(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return -1; | ||
} | ||
|
||
return by.length; | ||
} | ||
|
||
public int read(byte[] data){ | ||
if(fin==null){ | ||
return -1; | ||
} | ||
int length; | ||
try { | ||
length=fin.available(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return -1; | ||
} | ||
if(length==0){ | ||
return 0; | ||
} | ||
try { | ||
fin.read(data); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return data.length>length?length:data.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...u/hzuapps/androidworks/homeworks/net1314080903219/Net1314080903219MediaPlayerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903219; | ||
|
||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.media.MediaPlayer; | ||
import android.net.Uri; | ||
import android.os.Binder; | ||
import android.os.Environment; | ||
import android.os.IBinder; | ||
import android.widget.Toast; | ||
|
||
import java.io.IOException; | ||
|
||
import static android.support.v4.app.ActivityCompat.startActivityForResult; | ||
|
||
public class Net1314080903219MediaPlayerService extends Service { | ||
MediaPlayer player = new MediaPlayer(); | ||
|
||
public Net1314080903219MediaPlayerService() { | ||
|
||
/* try { | ||
player.reset(); | ||
player.setDataSource(path); | ||
player.prepare(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
}*/ | ||
} | ||
|
||
|
||
@Override | ||
public IBinder onBind(Intent arg0) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
//在这里我们需要实例化MediaPlayer对象 | ||
public void onCreate(){ | ||
|
||
super.onCreate(); | ||
//我们从raw文件夹中获取一个应用自带的mp3文件 | ||
|
||
System.out.println("sfsfsfsf dsf fdfd fsdf sf ffsfs"); | ||
|
||
|
||
} | ||
|
||
/** | ||
* 该方法在SDK2.0才开始有的,替代原来的onStart方法 | ||
*/ | ||
public int onStartCommand(Intent intent, int flags, int startId){ | ||
if(!player.isPlaying()){ | ||
// System.out.println(String.valueOf(intent.getCharSequenceArrayExtra("song"))); | ||
try { | ||
player.reset(); | ||
player.setDataSource(intent.getStringExtra("song")); | ||
player.prepare(); | ||
player.start(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return START_STICKY; | ||
} | ||
|
||
public void onDestroy(){ | ||
//super.onDestroy(); | ||
if(player.isPlaying()){ | ||
player.stop(); | ||
} | ||
player.release(); | ||
} | ||
|
||
|
||
|
||
|
||
//后退播放进度 | ||
public void haveFun(){ | ||
if(player.isPlaying() && player.getCurrentPosition()>2500){ | ||
player.seekTo(player.getCurrentPosition()-2500); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.