Skip to content

Commit

Permalink
playback controls
Browse files Browse the repository at this point in the history
  • Loading branch information
nheid committed Feb 12, 2011
1 parent e65d9cd commit c734107
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
gen
bin
local.properties
.project
.directory
.classpath
out
.idea
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="com.unitedcoders.android.gpodroid" android:versionCode="2"
android:versionName="0.1beta">
<uses-sdk android:minSdkVersion="7"/>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false" >
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" >
<activity android:name=".activity.Player" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
39 changes: 39 additions & 0 deletions GpodRoid.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="PLATFORM_NAME" value="Android 2.2 Platform" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/assets" />
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/libs" />
<option name="REGENERATE_R_JAVA" value="true" />
<option name="REGENERATE_JAVA_BY_AIDL" value="true" />
<option name="USE_CUSTOM_APK_RESOURCE_FOLDER" value="false" />
<option name="CUSTOM_APK_RESOURCE_FOLDER" value="" />
<option name="USE_CUSTOM_COMPILER_MANIFEST" value="false" />
<option name="CUSTOM_COMPILER_MANIFEST" value="" />
<option name="APK_PATH" value="" />
<option name="ADD_ANDROID_LIBRARY" value="true" />
<option name="LIBRARY_PROJECT" value="false" />
<option name="RUN_PROCESS_RESOURCES_MAVEN_TASK" value="true" />
<option name="GENERATE_UNSIGNED_APK" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jars" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Android 2.2 Platform" level="application" />
</component>
</module>

Binary file added res/drawable-hdpi/backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/fastbackward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/fastforward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/forward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/fastbackward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/fastforward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/forward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/fastbackward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/fastforward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/forward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 36 additions & 25 deletions res/layout/playerview.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
android:layout_width="fill_parent" android:layout_height="fill_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerInParent="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerInParent="true">

<TextView android:id="@+id/plain1" android:text="Now Playing:"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView android:id="@+id/plain1" android:text="Now Playing:"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/>

<TextView android:id="@+id/PodcastTitle" android:text="Podcast Title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="18dip" android:layout_gravity="center" />
<TextView android:id="@+id/PodcastTitle" android:text="Podcast Title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="18dip" android:layout_gravity="center"/>

<TextView android:id="@+id/EpisodeName" android:text="Episode Name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:textSize="20dip" />
<TextView android:id="@+id/space" android:text=""
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView android:id="@+id/EpisodeName" android:text="Episode Name"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:textSize="20dip"/>
<TextView android:id="@+id/space" android:text=""
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerInParent="true"
android:gravity="center">
<ImageButton android:id="@+id/buttonPlay" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerInParent="true"
android:gravity="center">

<ImageView android:id="@+id/podcastPicture"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#660066" />
<ImageButton android:id="@+id/btn_backward" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/fastbackward"/>
<ImageButton android:id="@+id/btn_forward" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/fastforward"/>

<Button android:id="@+id/buttonPlay" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Pause" />
</LinearLayout>

</LinearLayout>
</LinearLayout>


<Button android:id="@+id/btn_podcasts" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Podcasts"
android:onClick="openPodcastManager" android:layout_alignParentBottom="true" />
<Button android:id="@+id/btn_podcasts" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Podcasts"
android:onClick="openPodcastManager" android:layout_alignParentBottom="true"/>


</RelativeLayout>
Expand Down
29 changes: 22 additions & 7 deletions src/com/unitedcoders/android/gpodroid/PodcastElement.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package com.unitedcoders.android.gpodroid;

import java.io.File;


public class PodcastElement implements Comparable<PodcastElement> {

private String title = "";
private String downloadUrl;
private String album;
private String file;


private int seekPosition = 0;


public PodcastElement(String title, String downloadUrl) {
this.title = title;
this.downloadUrl = downloadUrl;

}

public PodcastElement(File file) {

}

public int getSeekPosition() {
return seekPosition;
}

public void setSeekPosition(int seekPosition) {
this.seekPosition = seekPosition;
}

public String getFile() {
return file;
Expand Down Expand Up @@ -37,11 +57,6 @@ public void setDownloadurl(String downloadurl) {

}

public PodcastElement(String title, String downloadUrl) {
this.title = title;
this.downloadUrl = downloadUrl;

}

@Override
public int compareTo(PodcastElement another) {
Expand Down
1 change: 1 addition & 0 deletions src/com/unitedcoders/android/gpodroid/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void setPreferences(Preferences preferences) {
private String password = "";
private String device = "";


private Preferences() {

}
Expand Down
115 changes: 87 additions & 28 deletions src/com/unitedcoders/android/gpodroid/activity/Player.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
package com.unitedcoders.android.gpodroid.activity;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.unitedcoders.android.gpodroid.GpodRoid;
import com.unitedcoders.android.gpodroid.PodcastElement;
import com.unitedcoders.android.gpodroid.Preferences;
import com.unitedcoders.android.gpodroid.R;
import com.unitedcoders.android.gpodroid.tools.PodcastUtil;

/**
* Shows the MediaPlayer and controls
*
*
* @author Nico Heid
*
*/
public class Player extends Activity {
public class Player extends Activity implements OnClickListener {

// private static File podcast;
private static MediaPlayer mp = new MediaPlayer();

// the playback queue
public static ArrayList<PodcastElement> playbackQueue = new ArrayList<PodcastElement>();
// Element playing
public static PodcastElement pce;
private int seekPosition = 0;

private TextView title;
private TextView episode;

// Buttons
private ImageButton forward;
private ImageButton backward;
private ImageButton buttonStop;

// private static boolean mpIsPlaying = false;
TextView title;
TextView episode;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview);


SharedPreferences settings = getApplicationContext().getSharedPreferences("PLAYBACKSTATE", 0);
String file = settings.getString("FILE", "");
seekPosition = settings.getInt("SEEKPOSITION", 0);

if (!file.equals("")) {
pce = PodcastUtil.getPodcastInfo(new File(file));
}


// load preferences
GpodRoid.prefs = Preferences.getPreferences(getApplicationContext());

Expand All @@ -56,56 +74,80 @@ protected void onCreate(Bundle savedInstanceState) {
episode = (TextView) findViewById(R.id.EpisodeName);
title = (TextView) findViewById(R.id.PodcastTitle);

// pretend state is empty
forward = (ImageButton) findViewById(R.id.btn_forward);
backward = (ImageButton) findViewById(R.id.btn_backward);
buttonStop = (ImageButton) findViewById(R.id.buttonPlay);


forward.setOnClickListener(this);
backward.setOnClickListener(this);

final Button buttonStop = (Button) findViewById(R.id.buttonPlay);
buttonStop.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()){
if (mp.isPlaying()) {
mp.pause();
buttonStop.setText("Play");
}else{
buttonStop.setBackgroundResource(R.drawable.play);
SharedPreferences settings = getApplicationContext().getSharedPreferences("PLAYBACKSTATE", 0);
SharedPreferences.Editor editor = settings.edit();

editor.putString("FILE", pce.getFile());
editor.putInt("SEEKPOSITION", mp.getCurrentPosition());
editor.commit();


} else {
mp.start();
buttonStop.setText("Pause");
buttonStop.setBackgroundResource(R.drawable.pause);
}


}
});



play();

}

@Override
protected void onDestroy() {
if (pce != null) {
// save playback state
SharedPreferences settings = getApplicationContext().getSharedPreferences("PLAYBACKSTATE", 0);
SharedPreferences.Editor editor = settings.edit();

editor.putString("FILE", pce.getFile());
editor.putInt("SEEKPOSITION", mp.getCurrentPosition());
editor.commit();
}

super.onDestroy();

}

private void play() {

if (playbackQueue.size() == 0) {
if (pce == null) {
return;
}

PodcastElement playingNow = playbackQueue.get(0);


try {
mp.reset();
mp.setDataSource(playingNow.getFile());
mp.setDataSource(pce.getFile());
mp.prepare();
mp.seekTo(seekPosition);
mp.start();
buttonStop.setBackgroundResource(R.drawable.pause);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

episode.setText(playingNow.getAlbum());
title.setText(playingNow.getTitle());

playbackQueue.remove(0);

episode.setText(pce.getAlbum());
title.setText(pce.getTitle());

}

Expand All @@ -114,4 +156,21 @@ public void openPodcastManager(View v) {
startActivity(intent);
}

@Override
public void onClick(View view) {


if (view == backward) {
seek(-15000);
} else if (view == forward) {
seek(+15000);
}


}

private void seek(int seek) {
int position = mp.getCurrentPosition();
mp.seekTo(position + seek);
}
}
Loading

0 comments on commit c734107

Please sign in to comment.