diff --git a/README.md b/README.md index ba38bb4..01da239 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,5 @@ This is agains YT terms of service and could not be present on Google Play Store Application provides mechanisms for searching videos and playlists on YT, as well as logging into a Google account in order to acquire private playlists, which normally cannot be accessed. -alt text -alt text - +alt text +alt text diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cbccb8b..39e8c20 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,5 +35,11 @@ android:name=".BackgroundAudioService" android:process=":youtube"> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java b/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java index 5d27e17..c33d9af 100644 --- a/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java +++ b/app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java @@ -18,6 +18,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -34,6 +35,7 @@ import android.util.Log; import android.util.SparseArray; +import com.smedic.tubtub.receivers.MediaButtonIntentReceiver; import com.smedic.tubtub.utils.Config; import com.squareup.picasso.Picasso; import com.squareup.picasso.Target; @@ -130,7 +132,6 @@ private void handleIntent(Intent intent) { * @param intent */ private void handleMedia(Intent intent) { - int intentMediaType = intent.getIntExtra(Config.YOUTUBE_MEDIA_TYPE, Config.YOUTUBE_NO_NEW_REQUEST); switch (intentMediaType) { case Config.YOUTUBE_NO_NEW_REQUEST: //video is paused,so no new playback requests should be processed @@ -166,7 +167,17 @@ private void initMediaSessions() { // permission in AndroidManifest.xml. mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); - mSession = new MediaSessionCompat(getApplicationContext(), "simple player session"); + ComponentName eventReceiver = new ComponentName(getApplicationContext().getPackageName(), + MediaButtonIntentReceiver.class.getName()); + PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast( + getApplicationContext(), + 0, + new Intent(Intent.ACTION_MEDIA_BUTTON), + PendingIntent.FLAG_UPDATE_CURRENT + ); + + mSession = new MediaSessionCompat(getApplicationContext(), "simple player session", + eventReceiver, buttonReceiverIntent); try { mController = new MediaControllerCompat(getApplicationContext(), mSession.getSessionToken()); @@ -181,6 +192,7 @@ public void onPlay() { @Override public void onPause() { + super.onPause(); pauseVideo(); buildNotification(generateAction(android.R.drawable.ic_media_play, "Play", ACTION_PLAY)); @@ -252,6 +264,7 @@ private void buildNotification(NotificationCompat.Action action) { builder.setShowWhen(false); builder.setContentIntent(clickPendingIntent); builder.setDeleteIntent(stopPendingIntent); + builder.setOngoing(false); builder.setStyle(style); //load bitmap for largeScreen @@ -274,19 +287,9 @@ public void onPrepareLoad(Drawable drawable) { }); } - if (mediaType == Config.YOUTUBE_PLAYLIST) { - builder.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS)); - } else { - builder.addAction(0, null, null); - } - + builder.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS)); builder.addAction(action); - - if (mediaType == Config.YOUTUBE_PLAYLIST) { - builder.addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT)); - } else { - builder.addAction(0, null, null); - } + builder.addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT)); style.setShowActionsInCompactView(0, 1, 2); @@ -328,7 +331,6 @@ private NotificationCompat.Action generateAction(int icon, String title, String * Plays next video */ private void playNext() { - if (previousWasCalled) { previousWasCalled = false; iterator.next(); @@ -347,7 +349,6 @@ private void playNext() { * Plays previous video */ private void playPrevious() { - if (nextWasCalled) { iterator.previous(); nextWasCalled = false; @@ -398,6 +399,7 @@ private void stopPlayer() { * Extracts link from youtube video ID, so mediaPlayer can play it */ private void extractUrlAndPlay() { + Log.d(TAG, "extract url"); String youtubeLink = "http://youtube.com/watch?v=" + videoItem.getId(); YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) { @Override diff --git a/app/src/main/java/com/smedic/tubtub/database/YouTubeSqlDb.java b/app/src/main/java/com/smedic/tubtub/database/YouTubeSqlDb.java index a16c35b..d4ed7b6 100644 --- a/app/src/main/java/com/smedic/tubtub/database/YouTubeSqlDb.java +++ b/app/src/main/java/com/smedic/tubtub/database/YouTubeSqlDb.java @@ -125,6 +125,9 @@ private Videos(String tableName) { * @return */ public boolean create(YouTubeVideo video) { + if(checkIfExists(video.getId())){ + return false; + } // Gets the data repository in write mode SQLiteDatabase db = dbHelper.getWritableDatabase(); diff --git a/app/src/main/java/com/smedic/tubtub/receivers/MediaButtonIntentReceiver.java b/app/src/main/java/com/smedic/tubtub/receivers/MediaButtonIntentReceiver.java new file mode 100644 index 0000000..7a3f7ea --- /dev/null +++ b/app/src/main/java/com/smedic/tubtub/receivers/MediaButtonIntentReceiver.java @@ -0,0 +1,16 @@ +package com.smedic.tubtub.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +/** + * Created by smedic on 23.3.16.. + */ +public class MediaButtonIntentReceiver extends BroadcastReceiver{ + @Override + public void onReceive(Context context, Intent intent) { + Log.d("SMEDIC" , "onRecive"); + } +} diff --git a/raw/Screenshot_2016-03-16-12-14-41.png b/raw/Screenshot_2016-03-16-12-14-41.png deleted file mode 100644 index b596022..0000000 Binary files a/raw/Screenshot_2016-03-16-12-14-41.png and /dev/null differ diff --git a/raw/Screenshot_2016-03-16-12-14-49.png b/raw/Screenshot_2016-03-16-12-14-49.png deleted file mode 100644 index 7b47ca6..0000000 Binary files a/raw/Screenshot_2016-03-16-12-14-49.png and /dev/null differ diff --git a/raw/Screenshot_2016-03-24-10-20-31.png b/raw/Screenshot_2016-03-24-10-20-31.png new file mode 100644 index 0000000..ee11d73 Binary files /dev/null and b/raw/Screenshot_2016-03-24-10-20-31.png differ diff --git a/raw/Screenshot_2016-03-24-10-21-27.png b/raw/Screenshot_2016-03-24-10-21-27.png new file mode 100644 index 0000000..e0b9244 Binary files /dev/null and b/raw/Screenshot_2016-03-24-10-21-27.png differ