Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
LogAnd1 committed Jan 9, 2018
2 parents 29c36e8 + fab7503 commit 7e91cd2
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
<activity
android:name=".PodcastList"
android:label="@string/title_activity_podcast_list"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MP3Activity"
android:label="MP3 Player"
android:theme="@style/AppTheme.NoActionBar" />
</application>

</manifest>
104 changes: 104 additions & 0 deletions app/src/main/java/com/example/pp/podcastplayer/MP3Activity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package com.example.pp.podcastplayer;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class MP3Activity extends AppCompatActivity {
String path_mp3 = "";
String path_slika = "";
String naslov = "";
MediaPlayer MP = new MediaPlayer();
Timer timer = new Timer();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -16,6 +34,92 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);


ImageView IV = (ImageView) findViewById(R.id.slika);
ImageButton IBPlay = (ImageButton) findViewById(R.id.playbutton);
ImageButton IBPause = (ImageButton) findViewById(R.id.pausebutton);
TextView TVNaslov = (TextView) findViewById(R.id.naslovpesmi);
TextView TVDur = (TextView) findViewById(R.id.duration);
final TextView TVCurr = (TextView) findViewById(R.id.current);
IBPause.setVisibility(View.GONE);

Intent intent = getIntent();
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
path_mp3 = bundle.getString("mp3");
path_slika = bundle.getString("slika");
naslov = bundle.getString("naslov");
}
}

if(naslov!="" && path_slika!="" && path_mp3!=""){


try {
MP.setDataSource(path_mp3);
MP.prepare();
TVNaslov.setText(naslov);
TVDur.setText(MP.getDuration());
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()+path_slika);
IV.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}

}

IBPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!MP.isPlaying()){
MP.start();
ImageButton IBPause = (ImageButton) findViewById(R.id.pausebutton);
IBPause.setVisibility(View.VISIBLE);
ImageButton IBPlay = (ImageButton) findViewById(R.id.playbutton);
IBPause.setVisibility(View.GONE);

timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (MP != null && MP.isPlaying()) {
TVCurr.post(new Runnable() {
@Override
public void run() {
TVCurr.setText(MP.getCurrentPosition());
}
});
} else {
timer.cancel();
timer.purge();
}
}
});
}
}, 0, 1000);


}
}
});

IBPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(MP.isPlaying()){
MP.pause();
ImageButton IBPause = (ImageButton) findViewById(R.id.pausebutton);
IBPause.setVisibility(View.GONE);
ImageButton IBPlay = (ImageButton) findViewById(R.id.playbutton);
IBPause.setVisibility(View.VISIBLE);
}
}
});

}

@Override
Expand Down
90 changes: 90 additions & 0 deletions app/src/main/res/layout/content_mp3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,94 @@
tools:context="com.example.pp.podcastplayer.MP3Activity"
tools:showIn="@layout/activity_mp3">

<TextView
android:id="@+id/naslovpesmi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Naslov"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />

<ImageView
android:id="@+id/slika"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/naslovpesmi"
app:srcCompat="@drawable/side_nav_bar" />

<ImageView
android:id="@+id/imageView4"
android:layout_width="300dp"
android:layout_height="30dp"
app:layout_constraintBottom_toBottomOf="@+id/slika"
app:layout_constraintEnd_toEndOf="@+id/slika"
app:layout_constraintStart_toStartOf="@+id/slika"
app:srcCompat="@android:drawable/ic_media_pause" android:contentDescription="TODO"/>

<ImageButton
android:id="@+id/pausebutton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="false"
android:background="@android:drawable/toast_frame"
app:layout_constraintBottom_toBottomOf="@+id/slika"
app:layout_constraintEnd_toEndOf="@+id/slika"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="@+id/slika"
app:layout_constraintTop_toTopOf="@+id/slika"
app:srcCompat="@android:drawable/ic_media_pause" android:contentDescription="TODO"/>

<ImageButton
android:id="@+id/playbutton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:drawable/toast_frame"
app:layout_constraintBottom_toBottomOf="@+id/slika"
app:layout_constraintEnd_toEndOf="@+id/slika"
app:layout_constraintStart_toStartOf="@+id/slika"
app:layout_constraintTop_toTopOf="@+id/slika"
app:srcCompat="@android:drawable/ic_media_play" />

<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:text="0:00"
android:textColor="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="@+id/slika"
app:layout_constraintStart_toStartOf="@+id/slika" />

<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="3:43"
android:textColor="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="@+id/slika"
app:layout_constraintEnd_toEndOf="@+id/slika" />

</android.support.constraint.ConstraintLayout>

0 comments on commit 7e91cd2

Please sign in to comment.