Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kirodema.icyBeatsBE;
- import java.io.File;
- import java.io.FilenameFilter;
- import java.io.IOException;
- import java.util.ArrayList;
- import android.app.ListActivity;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.os.RemoteException;
- import android.util.Log;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class BackEnd extends ListActivity {
- private static final String MEDIA_PATH = new String("/sdcard/MP3");
- private ArrayList<String> songs = new ArrayList<String>();
- //private MediaPlayer mp = new MediaPlayer();
- //private int curPos;
- private IBEInterface mpInterface;
- private ServiceConnection mConnection = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
- mpInterface = null;
- }
- @Override
- public void onServiceConnected(ComponentName arg0, IBinder service) {
- printDebug("Service connectet");
- mpInterface = IBEInterface.Stub.asInterface((IBinder) service);
- printDebug("mpInterface erstellt");
- try {
- mpInterface.clearPlaylist();
- } catch (RemoteException e) {}
- updateSongList(new File(MEDIA_PATH));
- }
- };
- private static final FilenameFilter MP3_FILTER
- = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return (name.endsWith(".mp3"));
- }
- };
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- printDebug("App gestartet");
- setContentView(R.layout.songs);
- printDebug("ContentView gesetzt");
- Intent serv = new Intent(this, IBEService.class);
- printDebug("Intent für Service erstellt: " + serv.toString());
- this.bindService(serv, mConnection, Context.BIND_AUTO_CREATE);
- //startService(serv);
- //updateSongList(new File(MEDIA_PATH));
- setListAdapter(new ArrayAdapter<String>(this, R.layout.song_item, songs));
- //Collections.sort(songs);
- }
- //TODO
- public void updateSongList(File root) {
- if (root.isFile() && MP3_FILTER.accept(root.getParentFile(), root.getName())) {
- try {
- songs.add(root.getCanonicalPath());
- mpInterface.addSongPlaylist(root.getCanonicalPath());
- } catch (IOException e) {}
- catch (RemoteException e) {}
- } else if (root.isDirectory()) {
- for (File x : root.listFiles()) {
- updateSongList(x);
- }
- }
- }
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- try {
- mpInterface.playFile(position);
- } catch(RemoteException e) {
- Log.e(getString(R.string.app_name), e.getMessage());
- }
- }
- private void printDebug (String msg) {
- Log.d(getString(R.string.app_name), msg);
- }
- // private void playSong (String songpath) {
- // try {
- // mp.reset();
- // mp.setDataSource(songpath);
- // mp.prepare();
- // mp.start();
- //
- // mp.setOnCompletionListener(new OnCompletionListener() {
- // @Override
- // public void onCompletion(MediaPlayer arg0) {
- // playNextSong();
- // }
- // });
- //
- // } catch(IOException e) {}
- // }
- //
- // private void playNextSong() {
- // if (++curPos >= songs.size()) {
- // // Last song, just reset currentPosition
- // curPos = 0;
- // } else {
- // // Play next song
- // playSong(MEDIA_PATH + songs.get(curPos));
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement