├── app ├── .gitignore ├── libs │ ├── mp3agic-0.9.0.jar │ └── MyID3_for_Android.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── xd.png │ │ │ │ ├── album.png │ │ │ │ ├── track.bmp │ │ │ │ ├── track_1.png │ │ │ │ ├── track_2.png │ │ │ │ ├── track_2_min.png │ │ │ │ ├── line_divider.xml │ │ │ │ ├── layout_border.xml │ │ │ │ ├── ic_keyboard_arrow_up_black_24dp.xml │ │ │ │ ├── next_24dp.xml │ │ │ │ ├── pause_24dp.xml │ │ │ │ ├── previous_24dp.xml │ │ │ │ ├── ic_person_black_24dp.xml │ │ │ │ ├── music_note_24dp.xml │ │ │ │ ├── ic_shuffle_black_24dp.xml │ │ │ │ ├── play_arrow_24dp.xml │ │ │ │ ├── ic_search.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── layout │ │ │ │ ├── artist_fragment.xml │ │ │ │ ├── album_song_layout.xml │ │ │ │ ├── songs_fragment.xml │ │ │ │ ├── albums_fragment.xml │ │ │ │ ├── adapter_album_layout.xml │ │ │ │ ├── adapter_view_layout.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_album.xml │ │ │ │ └── activity_player.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── menu │ │ │ │ └── search_menu.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── assets │ │ │ └── fonts │ │ │ │ ├── DroidSans.ttf │ │ │ │ └── DroidSans-Bold.ttf │ │ ├── java │ │ │ ├── interfaces │ │ │ │ └── OnClickListen.java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── mediaplayer │ │ │ │ ├── fragments │ │ │ │ ├── ArtistFragment.java │ │ │ │ ├── AlbumsFragment.java │ │ │ │ └── SongsFragment.java │ │ │ │ ├── notification │ │ │ │ ├── Channel.java │ │ │ │ ├── NofiticationCenter.java │ │ │ │ └── NotiService.java │ │ │ │ ├── adapters │ │ │ │ ├── ViewPagerAdapter.java │ │ │ │ ├── SongAlbumAdapter.java │ │ │ │ ├── AlbumAdapter.java │ │ │ │ └── SongAdapter.java │ │ │ │ ├── models │ │ │ │ ├── Song.java │ │ │ │ └── DataReading.java │ │ │ │ └── activities │ │ │ │ ├── AlbumActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ └── PlayerActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── mediaplayer │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── mediaplayer │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── mp3agic ├── .gitignore ├── src │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── mp3agic │ │ └── MyClass.java └── build.gradle ├── settings.gradle ├── screenshots ├── s1.jpg ├── s2.jpg ├── s3.jpg ├── s4.jpg ├── s5.jpg └── s6.jpg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── encodings.xml ├── vcs.xml ├── misc.xml ├── runConfigurations.xml └── gradle.xml ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /mp3agic/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':mp3agic' 2 | -------------------------------------------------------------------------------- /screenshots/s1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s1.jpg -------------------------------------------------------------------------------- /screenshots/s2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s2.jpg -------------------------------------------------------------------------------- /screenshots/s3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s3.jpg -------------------------------------------------------------------------------- /screenshots/s4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s4.jpg -------------------------------------------------------------------------------- /screenshots/s5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s5.jpg -------------------------------------------------------------------------------- /screenshots/s6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/screenshots/s6.jpg -------------------------------------------------------------------------------- /app/libs/mp3agic-0.9.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/libs/mp3agic-0.9.0.jar -------------------------------------------------------------------------------- /mp3agic/src/main/java/com/example/mp3agic/MyClass.java: -------------------------------------------------------------------------------- 1 | package com.example.mp3agic; 2 | 3 | public class MyClass { 4 | } 5 | -------------------------------------------------------------------------------- /app/libs/MyID3_for_Android.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/libs/MyID3_for_Android.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/xd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/xd.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/album.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/album.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/track.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/track.bmp -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/track_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/track_1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/track_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/track_2.png -------------------------------------------------------------------------------- /app/src/main/assets/fonts/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/assets/fonts/DroidSans.ttf -------------------------------------------------------------------------------- /app/src/main/java/interfaces/OnClickListen.java: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public interface OnClickListen { 4 | void onClick(int position); 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/track_2_min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/drawable/track_2_min.png -------------------------------------------------------------------------------- /app/src/main/assets/fonts/DroidSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/assets/fonts/DroidSans-Bold.ttf -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed99ayman/Gramophone-MusicPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /mp3agic/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | 3 | dependencies { 4 | implementation fileTree(dir: 'libs', include: ['*.jar']) 5 | } 6 | 7 | sourceCompatibility = "7" 8 | targetCompatibility = "7" 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #303030 4 | #303131 5 | #8B949B 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | "Gramophone" 3 | android.support.design.widget.AppBarLayout$ScrollingViewBehavior 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/line_divider.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 23 11:51:36 EET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/artist_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/fragments/ArtistFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.fragments; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.view.View; 5 | 6 | public class ArtistFragment extends Fragment implements View.OnClickListener { 7 | @Override 8 | public void onClick(View v) { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/layout_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_keyboard_arrow_up_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/next_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pause_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/previous_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/notification/Channel.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.notification; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | public class Channel extends BroadcastReceiver { 8 | 9 | @Override 10 | public void onReceive(Context context, Intent intent) { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_person_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/music_note_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/search_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_shuffle_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/play_arrow_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/mediaplayer/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer; 2 | 3 | import org.junit.Test; 4 | 5 | import static junit.framework.TestCase.assertEquals; 6 | 7 | 8 | /** 9 | * Example local unit test, which will execute on the development machine (host). 10 | * 11 | * @see Testing documentation 12 | */ 13 | public class ExampleUnitTest { 14 | @Test 15 | public void additionIsCorrect() { 16 | assertEquals(4, 2 + 2); 17 | } 18 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/album_song_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/songs_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 18 | 19 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/albums_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/mediaplayer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static junit.framework.TestCase.assertEquals; 11 | 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | assertEquals("com.example.mediaplayer", appContext.getPackageName()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/notification/NofiticationCenter.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.notification; 2 | 3 | import android.app.Application; 4 | import android.app.NotificationChannel; 5 | import android.app.NotificationManager; 6 | import android.os.Build; 7 | 8 | 9 | public class NofiticationCenter extends Application { 10 | public static final String channel_1_ID="channel1"; 11 | 12 | 13 | 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | createNofitication(); 19 | } 20 | 21 | private void createNofitication(){ 22 | if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){ 23 | NotificationChannel ch1=new NotificationChannel(channel_1_ID,"Song", NotificationManager.IMPORTANCE_LOW); 24 | ch1.setDescription("HEY"); 25 | NotificationManager manager=getSystemService(NotificationManager.class); 26 | manager.createNotificationChannel(ch1); 27 | } 28 | 29 | } 30 | 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/adapters/ViewPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.adapters; 2 | 3 | import android.support.annotation.Nullable; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class ViewPagerAdapter extends FragmentPagerAdapter { 12 | 13 | private final Listfragments=new ArrayList<>(); 14 | private final Listtitles=new ArrayList<>(); 15 | 16 | public ViewPagerAdapter(FragmentManager fm) { 17 | super(fm); 18 | } 19 | 20 | @Override 21 | public Fragment getItem(int i) { 22 | return fragments.get(i); 23 | } 24 | 25 | @Nullable 26 | @Override 27 | public CharSequence getPageTitle(int position) { 28 | return titles.get(position); 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return titles.size(); 34 | } 35 | public void addFragment(Fragment fragment,String title){ 36 | fragments.add(fragment); 37 | titles.add(title); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.example.mediaplayer" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support:exifinterface:28.0.0' 26 | implementation 'com.android.support:design:28.0.0' 27 | implementation 'com.android.support:palette-v7:28.0.0' 28 | 29 | 30 | implementation 'com.android.support:support-media-compat:28.0.0' 31 | 32 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 36 | implementation 'com.android.support:recyclerview-v7:28.0.0' 37 | implementation 'com.github.bumptech.glide:glide:4.9.0' 38 | implementation 'com.squareup.picasso:picasso:2.71828' 39 | 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3e8e29e3b85a49fbb21e98903627403e)](https://app.codacy.com/manual/Mohamed99ayman/Gramophone-MusicPlayer/dashboard?bid=15522340) 2 | 3 | # Gramophone-MusicPlayer 4 | A simple MusicPlayer that allows the user to select songs from their library and play them. 5 | 6 | ## Features ## 7 | - Supports all music file format. 8 | - Browse and play music by Albums. 9 | - Quick search for a song or artist. 10 | - Shuffle all your tracks. 11 | ## Libraries 12 | * [Design Support Library](https://developer.android.com/topic/libraries/support-library/features#design) 13 | The Design package provides APIs to add material design components and patterns. 14 | * [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html) 15 | A flexible view for providing a limited window into a large data set. 16 | * [Glide](https://github.com/bumptech/glide) 17 | An image loading and caching library for Android focused on smooth scrolling 18 | * [Palette](https://developer.android.com/reference/android/support/v7/graphics/Palette) 19 | A helper class to extract prominent colors from an image. 20 | 21 | # State 22 | Developing 23 | 24 | ## Screenshots ## 25 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s1.jpg) 26 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s2.jpg) 27 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s3.jpg) 28 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s4.jpg) 29 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s5.jpg) 30 | ![picture alt](https://github.com/Mohamed99ayman/Gramophone-MusicPlayer/blob/master/screenshots/s6.jpg) 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/adapter_album_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 17 | 25 | 35 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/layout/adapter_view_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 19 | 33 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/fragments/AlbumsFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.fragments; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | 14 | import com.example.mediaplayer.R; 15 | import com.example.mediaplayer.activities.AlbumActivity; 16 | import com.example.mediaplayer.activities.MainActivity; 17 | import com.example.mediaplayer.adapters.AlbumAdapter; 18 | 19 | import interfaces.OnClickListen; 20 | 21 | public class AlbumsFragment extends Fragment implements OnClickListen { 22 | protected View v; 23 | protected RecyclerView recyclerView; 24 | 25 | ///////////////HERE 26 | protected RecyclerView.LayoutManager mmanager; 27 | protected static AlbumAdapter albumAdapter; 28 | 29 | @Override 30 | public void onCreate(@Nullable Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | } 33 | 34 | 35 | 36 | 37 | @Nullable 38 | @Override 39 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 40 | v=inflater.inflate(R.layout.albums_fragment,container,false); 41 | recyclerView = v.findViewById(R.id.albums_recycleview); 42 | recyclerView.setHasFixedSize(true); 43 | mmanager=new GridLayoutManager(getContext(),2); 44 | albumAdapter = new AlbumAdapter(this); 45 | recyclerView.setLayoutManager(mmanager); 46 | recyclerView.setAdapter(albumAdapter); 47 | return v; 48 | 49 | } 50 | @Override 51 | public void onClick(int position) { 52 | Intent intent=new Intent(MainActivity.getInstance(), AlbumActivity.class).putExtra("index",position); 53 | startActivity(intent); 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/models/Song.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.models; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | public class Song implements Comparable { 6 | 7 | 8 | private String name ,album, artist,path,AlbumArt; 9 | private long albumID; 10 | private int im; 11 | private Bitmap songImage; 12 | public Song(String name){ 13 | this.name=name; 14 | } 15 | 16 | public long getAlbumID() { 17 | return albumID; 18 | } 19 | 20 | public void setAlbumID(long albumID) { 21 | this.albumID = albumID; 22 | } 23 | 24 | public int getIm() { 25 | return im; 26 | } 27 | 28 | public void setIm(int im) { 29 | this.im = im; 30 | } 31 | 32 | 33 | 34 | public String getPath() { 35 | return path; 36 | } 37 | 38 | public void setPath(String path) { 39 | this.path = path; 40 | } 41 | 42 | public String getAlbumArt() { 43 | return AlbumArt; 44 | } 45 | 46 | public void setAlbumArt(String albumArt) { 47 | AlbumArt = albumArt; 48 | } 49 | 50 | public Bitmap getSongImage() { 51 | return songImage; 52 | } 53 | 54 | public void setSongImage(Bitmap songImage) { 55 | this.songImage = songImage; 56 | } 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | 66 | public String getAlbum() { 67 | return album; 68 | } 69 | 70 | public void setAlbum(String album) { 71 | this.album = album; 72 | } 73 | 74 | public String getArtist() { 75 | return artist; 76 | } 77 | 78 | public void setArtist(String artist) { 79 | this.artist = artist; 80 | } 81 | 82 | public Song(){ 83 | 84 | } 85 | public Song(String name, String album, String artist, String genre, int index) { 86 | this.name = name; 87 | this.album = album; 88 | this.artist = artist; 89 | 90 | } 91 | @Override 92 | public int compareTo(Song o) { 93 | return getName().compareTo(o.getName()); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/fragments/SongsFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.fragments; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | 15 | import com.example.mediaplayer.R; 16 | import com.example.mediaplayer.activities.MainActivity; 17 | import com.example.mediaplayer.activities.PlayerActivity; 18 | import com.example.mediaplayer.adapters.SongAdapter; 19 | 20 | 21 | import interfaces.OnClickListen; 22 | 23 | import static com.example.mediaplayer.adapters.SongAdapter.songs; 24 | 25 | public class SongsFragment extends Fragment implements OnClickListen { 26 | private View v; 27 | private RecyclerView recyclerView; 28 | private RecyclerView.LayoutManager mmanager; 29 | private static SongAdapter songAdapter; 30 | 31 | @Override 32 | public void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | } 35 | @Nullable 36 | @Override 37 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | v=inflater.inflate(R.layout.songs_fragment,container,false); 39 | recyclerView = v.findViewById(R.id.recycleview); 40 | recyclerView.setHasFixedSize(true); 41 | mmanager=new LinearLayoutManager(getContext()); 42 | songAdapter = new SongAdapter(MainActivity.getInstance(), songs,this); 43 | recyclerView.setLayoutManager(mmanager); 44 | recyclerView.setAdapter(songAdapter); 45 | return v; 46 | } 47 | 48 | 49 | @Override 50 | public void onClick(int position) { 51 | if(position>0) { 52 | Intent intent = new Intent(MainActivity.getInstance(), PlayerActivity.class).putExtra("index", position).putExtra("val", 0).putExtra("from",true); 53 | startActivity(intent); 54 | } 55 | else{ 56 | Intent intent = new Intent(MainActivity.getInstance(), PlayerActivity.class).putExtra("index", position).putExtra("val", 2).putExtra("from",true); 57 | startActivity(intent); 58 | } 59 | } 60 | public static void search(String text){ 61 | songAdapter.getFilter().filter(text); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/models/DataReading.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.models; 2 | import android.content.Context; 3 | import android.database.Cursor; 4 | import android.net.Uri; 5 | import android.provider.MediaStore; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | 11 | 12 | public class DataReading { 13 | 14 | private Context context; 15 | private HashMap>albums=new HashMap<>(); 16 | private HashMap>Artists=new HashMap<>(); 17 | 18 | 19 | public HashMap> getAlbums() { 20 | return albums; 21 | } 22 | 23 | public void setAlbums(HashMap> albums) { 24 | this.albums = albums; 25 | } 26 | public DataReading(Context context){ 27 | this.context=context; 28 | } 29 | 30 | 31 | public ArrayList getAllAudioFromDevice() { 32 | final ArrayList songs = new ArrayList<>(); 33 | 34 | Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 35 | String[] projection = {MediaStore.Audio.AudioColumns.DATA,MediaStore.Audio.AudioColumns.TITLE ,MediaStore.Audio.AudioColumns.ALBUM, MediaStore.Audio.ArtistColumns.ARTIST,MediaStore.Audio.AudioColumns.ALBUM_ID}; 36 | Cursor c = context.getContentResolver().query(uri, projection, null, null, null); 37 | 38 | if (c != null) { 39 | while (c.moveToNext()) { 40 | Song audioModel = new Song(); 41 | String path = c.getString(0); // Retrieve path. 42 | String name = c.getString(1); // Retrieve name. 43 | String album = c.getString(2); // Retrieve album name. 44 | String artist = c.getString(3); // Retrieve artist name. 45 | Long albumID=c.getLong(4); 46 | audioModel.setName(name); 47 | audioModel.setAlbum(album); 48 | audioModel.setArtist(artist); 49 | audioModel.setPath(path); 50 | audioModel.setAlbumID(albumID); 51 | songs.add(audioModel); 52 | if(albums.get(album)==null){ 53 | albums.put(album,new ArrayList()); 54 | } 55 | albums.get(album).add(audioModel); 56 | if(Artists.get(artist)==null){ 57 | Artists.put(artist,new ArrayList()); 58 | } 59 | Artists.get(artist).add(audioModel); 60 | } 61 | c.close(); 62 | } 63 | return songs; 64 | } 65 | } 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/notification/NotiService.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.notification; 2 | import android.app.Service; 3 | import android.content.Intent; 4 | import android.os.IBinder; 5 | import android.support.annotation.Nullable; 6 | 7 | import com.example.mediaplayer.activities.MainActivity; 8 | import com.example.mediaplayer.activities.PlayerActivity; 9 | import com.example.mediaplayer.adapters.SongAdapter; 10 | 11 | public class NotiService extends Service { 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | } 17 | 18 | @Override 19 | public int onStartCommand(Intent intent, int flags, int startId) { 20 | String input = intent.getStringExtra("inputExtra"); 21 | Intent notificationIntent = new Intent(this, MainActivity.class); 22 | 23 | 24 | handleIncomingActions(intent); 25 | 26 | return START_NOT_STICKY; 27 | } 28 | private void handleIncomingActions(Intent playbackAction) { 29 | if (playbackAction == null || playbackAction.getAction() == null) return; 30 | int pos= PlayerActivity.getInstance().getPosition(); 31 | 32 | String actionString = playbackAction.getAction(); 33 | 34 | if (actionString.equalsIgnoreCase("com.mypackage.ACTION_PAUSE_MUSIC")) { 35 | if( PlayerActivity.playin){ 36 | PlayerActivity.getInstance().pause(); 37 | } 38 | else{ 39 | PlayerActivity.getInstance().play(); 40 | } 41 | } else if (actionString.equalsIgnoreCase("com.mypackage.ACTION_NEXT_MUSIC")) { 42 | if(SongAdapter.songs.get((pos+1)% SongAdapter.songs.size()).getName().equals("shufflee"))pos++; 43 | PlayerActivity.getInstance().initPlayer(((pos+1)% SongAdapter.songs.size())); 44 | PlayerActivity.getInstance().setPosition(((pos+1)% SongAdapter.songs.size())); 45 | } else if (actionString.equalsIgnoreCase("com.mypackage.ACTION_PREV_MUSIC")) { 46 | if(SongAdapter.songs.get((pos+1)% SongAdapter.songs.size()).getName().equals("shufflee"))pos--; 47 | if(pos<=0)pos=SongAdapter.songs.size()-1; 48 | else pos-=1; 49 | PlayerActivity.getInstance().setPosition(pos); 50 | PlayerActivity.getInstance().initPlayer((pos)); 51 | } 52 | } 53 | 54 | 55 | @Override 56 | public void onDestroy() { 57 | super.onDestroy(); 58 | } 59 | 60 | @Nullable 61 | @Override 62 | public IBinder onBind(Intent intent) { 63 | return null; 64 | } 65 | 66 | 67 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/adapters/SongAlbumAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.adapters; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.Filter; 9 | import android.widget.Filterable; 10 | import android.widget.TextView; 11 | 12 | import com.example.mediaplayer.R; 13 | import com.example.mediaplayer.activities.MainActivity; 14 | import com.example.mediaplayer.models.Song; 15 | 16 | import java.util.ArrayList; 17 | 18 | import interfaces.OnClickListen; 19 | 20 | import static com.example.mediaplayer.adapters.SongAdapter.myfont; 21 | 22 | public class SongAlbumAdapter extends RecyclerView.Adapter implements Filterable { 23 | 24 | private OnClickListen alclicklisten; 25 | public static ArrayList albumSong; 26 | private static LayoutInflater inflater=null; 27 | public SongAlbumAdapter(ArrayListalbumSong,OnClickListen alclicklisten){ 28 | this.alclicklisten = alclicklisten; 29 | inflater=(LayoutInflater) MainActivity.getInstance().getSystemService(MainActivity.getInstance().LAYOUT_INFLATER_SERVICE); 30 | this.albumSong=albumSong; 31 | } 32 | 33 | @NonNull 34 | @Override 35 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { 36 | View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.album_song_layout,viewGroup,false); 37 | return new SongAlbumAdapter.ViewHolder(view,alclicklisten); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { 42 | Song song= albumSong.get(i); 43 | viewHolder.textView.setText(" - "+song.getName()); 44 | 45 | } 46 | 47 | @Override 48 | public int getItemCount() { 49 | return albumSong.size(); 50 | } 51 | 52 | @Override 53 | public Filter getFilter() { 54 | return null; 55 | } 56 | 57 | 58 | public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 59 | public TextView textView; 60 | OnClickListen onClickListen; 61 | public ViewHolder(@NonNull View itemView, OnClickListen onClickListen) { 62 | super(itemView); 63 | textView=itemView.findViewById(R.id.text_song); 64 | textView.setTypeface(myfont); 65 | this.onClickListen=onClickListen; 66 | itemView.setOnClickListener(this); 67 | 68 | } 69 | 70 | 71 | @Override 72 | public void onClick(View v) { 73 | onClickListen.onClick(getAdapterPosition()); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 27 | 28 | 34 | 35 | 44 | 45 | 54 | 55 | 70 | 71 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/adapters/AlbumAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.adapters; 2 | 3 | import android.content.ContentUris; 4 | import android.net.Uri; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Filter; 11 | import android.widget.Filterable; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | 15 | import com.bumptech.glide.Glide; 16 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 17 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; 18 | import com.bumptech.glide.request.RequestOptions; 19 | import com.example.mediaplayer.R; 20 | import com.example.mediaplayer.models.Song; 21 | import com.example.mediaplayer.activities.MainActivity; 22 | 23 | 24 | import interfaces.OnClickListen; 25 | 26 | public class AlbumAdapter extends RecyclerView.Adapter implements Filterable { 27 | private OnClickListen alclicklisten; 28 | //for search 29 | //ArrayList>filtered=new ArrayList<>(); 30 | 31 | private LayoutInflater inflater; 32 | 33 | public AlbumAdapter(OnClickListen alclicklisten) { 34 | this.alclicklisten = alclicklisten; 35 | inflater=(LayoutInflater) MainActivity.getInstance().getSystemService(MainActivity.getInstance().LAYOUT_INFLATER_SERVICE); 36 | } 37 | 38 | @NonNull 39 | @Override 40 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { 41 | 42 | View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_album_layout,viewGroup,false); 43 | return new ViewHolder(view,alclicklisten); 44 | 45 | } 46 | 47 | @Override 48 | public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { 49 | 50 | Song song=MainActivity.al.get(i).get(0); 51 | viewHolder.album.setText(song.getAlbum()); 52 | viewHolder.artist.setText(song.getArtist()); 53 | Glide 54 | .with(MainActivity.getInstance()) 55 | .load(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"),song.getAlbumID()).toString()) 56 | .apply(new RequestOptions() 57 | .placeholder(R.drawable.xd) 58 | .diskCacheStrategy(DiskCacheStrategy.NONE) 59 | .skipMemoryCache(true) 60 | ) 61 | .thumbnail(0.1f) 62 | .transition(new DrawableTransitionOptions() 63 | .crossFade() 64 | ) 65 | .into(viewHolder.imageView); 66 | } 67 | 68 | @Override 69 | public int getItemCount() { 70 | return MainActivity.al.size(); 71 | } 72 | 73 | @Override 74 | public Filter getFilter() { 75 | return null; 76 | } 77 | 78 | 79 | public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 80 | private TextView album,artist; 81 | private ImageView imageView; 82 | private OnClickListen onClickListen; 83 | public ViewHolder(@NonNull View itemView,OnClickListen onClickListen) { 84 | super(itemView); 85 | album=itemView.findViewById(R.id.album_name); 86 | artist=itemView.findViewById(R.id.album_artist); 87 | imageView=itemView.findViewById(R.id.album_image); 88 | this.onClickListen=onClickListen; 89 | itemView.setOnClickListener(this); 90 | } 91 | 92 | @Override 93 | public void onClick(View v) { 94 | onClickListen.onClick(getAdapterPosition()); 95 | } 96 | } 97 | /* private Filter filter=new Filter() { 98 | @Override 99 | protected FilterResults performFiltering(CharSequence constraint) { 100 | if (constraint == null || constraint.length() == 0) { 101 | filtered = MainActivity.al; 102 | } else { 103 | String filterpattern = constraint.toString().toLowerCase().trim(); 104 | for (int i=0;i 2 | 3 | 9 | 10 | 11 | 16 | 23 | 24 | 25 | 33 | 42 | 50 | 57 | 62 | 69 | 70 | 76 | 81 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 20 | 21 | 26 | 31 | 32 | 33 | 45 | 57 | 58 | 59 | 60 | 66 | 71 | 78 | 86 | 94 | 102 | 111 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/activities/AlbumActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.activities; 2 | import android.content.ContentUris; 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Color; 6 | import android.graphics.drawable.BitmapDrawable; 7 | import android.graphics.drawable.Drawable; 8 | import android.net.Uri; 9 | import android.os.Bundle; 10 | import android.support.annotation.Nullable; 11 | import android.support.v4.content.ContextCompat; 12 | import android.support.v7.app.AppCompatActivity; 13 | import android.support.v7.graphics.Palette; 14 | import android.support.v7.widget.DividerItemDecoration; 15 | import android.support.v7.widget.LinearLayoutManager; 16 | import android.support.v7.widget.RecyclerView; 17 | import android.text.TextUtils; 18 | import android.widget.ImageView; 19 | import android.widget.LinearLayout; 20 | import android.widget.TextView; 21 | 22 | import com.bumptech.glide.Glide; 23 | import com.bumptech.glide.load.DataSource; 24 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 25 | import com.bumptech.glide.load.engine.GlideException; 26 | import com.bumptech.glide.request.RequestListener; 27 | import com.bumptech.glide.request.target.Target; 28 | import com.example.mediaplayer.R; 29 | import com.example.mediaplayer.adapters.SongAlbumAdapter; 30 | import interfaces.OnClickListen; 31 | import static com.example.mediaplayer.activities.MainActivity.al; 32 | 33 | public class AlbumActivity extends AppCompatActivity implements OnClickListen { 34 | 35 | 36 | protected ImageView imageView; 37 | protected int position; 38 | private TextView textView1,textView2; 39 | protected RecyclerView recyclerView; 40 | protected RecyclerView.LayoutManager mmanager; 41 | private LinearLayout linearLayout; 42 | static SongAlbumAdapter songalbumAdapter; 43 | private Palette.Swatch lightVibrantSwatch; 44 | private Palette.Swatch darkMutedSwatch; 45 | 46 | 47 | 48 | @Override 49 | protected void onCreate(@Nullable Bundle savedInstanceState) { 50 | super.onCreate(savedInstanceState); 51 | setContentView(R.layout.activity_album); 52 | recyclerView = findViewById(R.id.album_recycler); 53 | imageView=findViewById(R.id.albumimage); 54 | linearLayout=findViewById(R.id.linear); 55 | recyclerView.setHasFixedSize(true); 56 | textView1=findViewById(R.id.text1); 57 | textView2=findViewById(R.id.text2); 58 | mmanager=new LinearLayoutManager(this); 59 | Intent i = getIntent(); 60 | Bundle bundle = i.getExtras(); 61 | position = bundle.getInt("index"); 62 | songalbumAdapter = new SongAlbumAdapter(al.get(position),this); 63 | System.out.println(al.get(position).get(0).getArtist()); 64 | textView1.setEllipsize(TextUtils.TruncateAt.MARQUEE); 65 | textView1.setText(al.get(position).get(0).getArtist()); 66 | String size=(al.get(position).size())+""; 67 | textView2.setText(size); 68 | 69 | Glide.with(this) 70 | .load(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"),al.get(position).get(0).getAlbumID()).toString()) 71 | .thumbnail(0.2f) 72 | .centerCrop() 73 | .placeholder(R.drawable.track) 74 | .skipMemoryCache(true) 75 | .diskCacheStrategy(DiskCacheStrategy.NONE) 76 | .listener(new RequestListener() { 77 | @Override 78 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { 79 | return false; 80 | } 81 | 82 | @Override 83 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { 84 | setBack(); 85 | return false; 86 | } 87 | }) 88 | .into(imageView); 89 | 90 | DividerItemDecoration verticalDecoration = new DividerItemDecoration(this, 91 | DividerItemDecoration.HORIZONTAL); 92 | Drawable verticalDivider = ContextCompat.getDrawable(this, R.drawable.line_divider); 93 | verticalDecoration.setDrawable(verticalDivider); 94 | recyclerView.addItemDecoration(verticalDecoration); 95 | 96 | recyclerView.setLayoutManager(mmanager); 97 | recyclerView.setAdapter(songalbumAdapter); 98 | 99 | 100 | } 101 | 102 | 103 | @Override 104 | public void onClick(int position) { 105 | Intent intent=new Intent(MainActivity.getInstance(), PlayerActivity.class).putExtra("index",position).putExtra("val",1).putExtra("from",true); 106 | startActivity(intent); 107 | } 108 | 109 | public void setBack(){ 110 | Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); 111 | 112 | Palette.from(bitmap).maximumColorCount(40).generate(new Palette.PaletteAsyncListener() { 113 | @Override 114 | public void onGenerated(Palette palette) { 115 | lightVibrantSwatch = palette.getLightVibrantSwatch(); 116 | darkMutedSwatch = palette.getDarkMutedSwatch(); 117 | if (lightVibrantSwatch != null) { 118 | linearLayout.setBackgroundColor(lightVibrantSwatch.getRgb()); 119 | 120 | } else { 121 | linearLayout.setBackgroundColor(Color.WHITE); 122 | } 123 | if(darkMutedSwatch!=null){ 124 | textView1.setTextColor(darkMutedSwatch.getRgb()); 125 | textView2.setTextColor(darkMutedSwatch.getRgb()); 126 | }else{ 127 | textView1.setTextColor(Color.BLACK); 128 | textView2.setTextColor(Color.BLACK); 129 | } 130 | 131 | } 132 | }); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/adapters/SongAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.adapters; 2 | import android.app.Activity; 3 | import android.content.ContentUris; 4 | import android.graphics.Color; 5 | import android.graphics.Typeface; 6 | import android.net.Uri; 7 | import android.support.annotation.NonNull; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Filter; 13 | import android.widget.Filterable; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | import com.bumptech.glide.Glide; 17 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 18 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; 19 | import com.bumptech.glide.request.RequestOptions; 20 | import com.example.mediaplayer.R; 21 | import com.example.mediaplayer.models.Song; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import interfaces.OnClickListen; 27 | 28 | public class SongAdapter extends RecyclerView.Adapter implements Filterable { 29 | protected static Typeface myfont; 30 | protected OnClickListen monclicklisten; 31 | private Activity context; 32 | public static ArrayListsongs; 33 | private ArrayListallSongs; 34 | private static LayoutInflater inflater; 35 | 36 | 37 | @NonNull 38 | @Override 39 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { 40 | View v=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_view_layout,viewGroup,false); 41 | ViewHolder vh=new ViewHolder(v,monclicklisten); 42 | return vh; 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { 47 | if(i==0){ 48 | viewHolder.textview1.setText("Shuffle All"); 49 | viewHolder.textView2.setText(""); 50 | 51 | viewHolder.textview1.setTextSize(25); 52 | viewHolder.textview1.setTextColor(Color.parseColor("#FF1105")); 53 | Glide 54 | .with(context) 55 | .load(R.drawable.ic_shuffle_black_24dp) 56 | .apply(new RequestOptions() 57 | .diskCacheStrategy(DiskCacheStrategy.NONE) 58 | .skipMemoryCache(true) 59 | ) 60 | .thumbnail(0.1f) 61 | .transition(new DrawableTransitionOptions() 62 | .crossFade() 63 | ) 64 | .into(viewHolder.mImageView); 65 | 66 | }else { 67 | Song song = songs.get(i); 68 | viewHolder.textview1.setX(viewHolder.textview1.getX()); 69 | viewHolder.textview1.setY(viewHolder.textview1.getY()); 70 | viewHolder.textview1.setTextSize(18); 71 | viewHolder.textview1.setText(song.getName()); 72 | viewHolder.textView2.setText(song.getArtist()); 73 | viewHolder.textView2.setX(viewHolder.textView2.getX()); 74 | viewHolder.textview1.setTextColor(Color.parseColor("#E7DBDB")); 75 | try { 76 | 77 | Glide 78 | .with(context) 79 | .load(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), song.getAlbumID()).toString()) 80 | .apply(new RequestOptions() 81 | .placeholder(R.drawable.track_2_min) 82 | .diskCacheStrategy(DiskCacheStrategy.NONE) 83 | .skipMemoryCache(true) 84 | ) 85 | .thumbnail(0.1f) 86 | .transition(new DrawableTransitionOptions() 87 | .crossFade() 88 | ) 89 | .into(viewHolder.mImageView); 90 | return; 91 | } catch (Exception e) { 92 | } 93 | } 94 | } 95 | @Override 96 | public int getItemCount() { 97 | return songs.size(); 98 | } 99 | 100 | public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 101 | public ImageView mImageView; 102 | public TextView textview1; 103 | public TextView textView2; 104 | OnClickListen onClickListen; 105 | public ViewHolder(@NonNull View itemView,OnClickListen onClickListen) { 106 | super(itemView); 107 | mImageView=itemView.findViewById(R.id.imageView); 108 | textview1=itemView.findViewById(R.id.textViewSongTitle); 109 | textview1.setTypeface(myfont); 110 | textView2=itemView.findViewById(R.id.textViewArtistName); 111 | this.onClickListen=onClickListen; 112 | itemView.setOnClickListener(this); 113 | } 114 | 115 | @Override 116 | public void onClick(View v) { 117 | onClickListen.onClick(getAdapterPosition()); 118 | } 119 | } 120 | 121 | 122 | 123 | public Song getSong(int position){ 124 | return allSongs.get(position); 125 | } 126 | 127 | public SongAdapter(Activity context, ArrayList song,OnClickListen onClickListen) { 128 | this.context = context; 129 | this.songs = song; 130 | allSongs=new ArrayList<>(song); 131 | inflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 132 | this.monclicklisten=onClickListen; 133 | 134 | } 135 | @Override 136 | public Filter getFilter(){ 137 | return filter; 138 | } 139 | private Filter filter=new Filter() { 140 | @Override 141 | protected FilterResults performFiltering(CharSequence constraint) { 142 | ListfilteredList=new ArrayList<>(); 143 | if(constraint==null||constraint.length()==0){ 144 | filteredList.addAll(allSongs); 145 | }else{ 146 | String filterpattern=constraint.toString().toLowerCase().trim(); 147 | 148 | for (Song oneSong:allSongs){ 149 | if(oneSong.getName().toLowerCase().startsWith(filterpattern)||oneSong.getArtist().toLowerCase().startsWith(filterpattern)){ 150 | filteredList.add(oneSong); 151 | } 152 | } 153 | 154 | } 155 | FilterResults filterResults=new FilterResults(); 156 | filterResults.values=filteredList; 157 | return filterResults; 158 | } 159 | 160 | @Override 161 | protected void publishResults(CharSequence constraint, FilterResults results) { 162 | songs.clear(); 163 | songs.add(new Song("shufflee")); 164 | songs.addAll((List)results.values); 165 | notifyDataSetChanged(); 166 | } 167 | }; 168 | 169 | } 170 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.activities; 2 | import android.Manifest; 3 | import android.app.Notification; 4 | import android.app.PendingIntent; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.content.pm.PackageManager; 8 | import android.graphics.Bitmap; 9 | import android.graphics.BitmapFactory; 10 | import android.media.MediaMetadataRetriever; 11 | import android.support.annotation.NonNull; 12 | import android.support.v4.app.ActivityCompat; 13 | import android.support.v4.app.NotificationCompat; 14 | import android.support.v4.app.NotificationManagerCompat; 15 | import android.support.v4.content.ContextCompat; 16 | import android.support.v4.media.session.MediaSessionCompat; 17 | import android.support.v4.view.MenuItemCompat; 18 | import android.support.v4.view.ViewPager; 19 | import android.support.v7.app.ActionBar; 20 | import android.support.v7.app.AlertDialog; 21 | import android.support.v7.app.AppCompatActivity; 22 | import android.os.Bundle; 23 | import android.view.Menu; 24 | import android.view.MenuInflater; 25 | import android.view.MenuItem; 26 | import android.view.View; 27 | import android.view.inputmethod.EditorInfo; 28 | import android.widget.ImageView; 29 | import android.widget.LinearLayout; 30 | import android.widget.TextView; 31 | import android.widget.Toast; 32 | import android.support.v7.widget.SearchView; 33 | import java.util.ArrayList; 34 | import java.util.Collections; 35 | import java.util.HashMap; 36 | import java.util.Iterator; 37 | import java.util.List; 38 | import java.util.Map; 39 | 40 | import android.support.design.widget.TabLayout; 41 | 42 | import com.example.mediaplayer.fragments.AlbumsFragment; 43 | import com.example.mediaplayer.models.DataReading; 44 | import com.example.mediaplayer.notification.NotiService; 45 | import com.example.mediaplayer.R; 46 | import com.example.mediaplayer.models.Song; 47 | import com.example.mediaplayer.adapters.SongAdapter; 48 | import com.example.mediaplayer.fragments.SongsFragment; 49 | import com.example.mediaplayer.adapters.ViewPagerAdapter; 50 | 51 | import static com.example.mediaplayer.notification.NofiticationCenter.channel_1_ID; 52 | import static com.example.mediaplayer.adapters.SongAdapter.songs; 53 | 54 | public class MainActivity extends AppCompatActivity { 55 | private int Storage_Permission_code=1; 56 | private static final String TAG = "MainActivity"; 57 | DataReading dataReading; 58 | protected static MainActivity instance; 59 | private byte arts[]; 60 | 61 | private HashMap >albums=new HashMap<>(); 62 | public static ArrayList>al=new ArrayList<>(); 63 | 64 | 65 | 66 | private NotificationManagerCompat notificationManager; 67 | MediaMetadataRetriever metadataRetriever; 68 | private MediaSessionCompat mediaSession; 69 | 70 | TabLayout tableLayout; 71 | ViewPager viewPager; 72 | protected ViewPagerAdapter viewPagerAdapter; 73 | LinearLayout miniplayer; 74 | TextView textView; 75 | public static ImageView imageView; 76 | public static Notification notification; 77 | 78 | @Override 79 | protected void onCreate(Bundle savedInstanceState) { 80 | super.onCreate(savedInstanceState); 81 | 82 | 83 | setContentView(R.layout.activity_main); 84 | textView=findViewById(R.id.mini_player_title); 85 | tableLayout=findViewById(R.id.table_Layout); 86 | viewPager=findViewById(R.id.view_Pager); 87 | viewPagerAdapter=new ViewPagerAdapter(getSupportFragmentManager()); 88 | 89 | 90 | viewPagerAdapter.addFragment(new SongsFragment(),"Songs"); 91 | viewPagerAdapter.addFragment(new AlbumsFragment(),"Albums"); 92 | 93 | viewPager.setAdapter(viewPagerAdapter); 94 | tableLayout.setupWithViewPager(viewPager); 95 | ActionBar actionBar=getSupportActionBar(); 96 | actionBar.setElevation(0); 97 | imageView=findViewById(R.id.mini_player_play_pause_button); 98 | miniplayer=findViewById(R.id.mini_player); 99 | imageView.setBackgroundResource(R.drawable.play_arrow_24dp); 100 | intializeMini(); 101 | notificationManager = NotificationManagerCompat.from(this); 102 | 103 | mediaSession = new MediaSessionCompat(this, "tag"); 104 | instance=this; 105 | 106 | if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_EXTERNAL_STORAGE)==PackageManager.PERMISSION_DENIED){ 107 | requestStoragePermission(); 108 | }else { 109 | start(); 110 | 111 | } 112 | } 113 | 114 | public void intializeMini(){ 115 | imageView.setOnClickListener(new View.OnClickListener() { 116 | @Override 117 | public void onClick(View v) { 118 | PlayerActivity.getInstance().play(); 119 | if(PlayerActivity.playin==true){ 120 | imageView.setBackgroundResource(R.drawable.pause_24dp); 121 | }else{ 122 | imageView.setBackgroundResource(R.drawable.play_arrow_24dp); 123 | 124 | } 125 | } 126 | }); 127 | 128 | miniplayer.setOnClickListener(new View.OnClickListener() { 129 | @Override 130 | public void onClick(View v) { 131 | Intent intent = new Intent(MainActivity.getInstance(), PlayerActivity.class).putExtra("index", 0).putExtra("val", 0).putExtra("from",false); 132 | startActivity(intent); 133 | } 134 | }); 135 | 136 | 137 | } 138 | public static MainActivity getInstance() { 139 | return instance; 140 | } 141 | 142 | private void requestStoragePermission(){ 143 | if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.READ_EXTERNAL_STORAGE)){ 144 | new AlertDialog.Builder(this).setTitle("Permission Needed").setMessage("Need to read songs from your storage").setPositiveButton("Okay", new DialogInterface.OnClickListener() { 145 | @Override 146 | public void onClick(DialogInterface dialog, int which) { 147 | ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},Storage_Permission_code); 148 | 149 | } 150 | }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 151 | @Override 152 | public void onClick(DialogInterface dialog, int which) { 153 | dialog.dismiss(); 154 | } 155 | }).create().show(); 156 | 157 | }else{ 158 | ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},Storage_Permission_code); 159 | } 160 | 161 | } 162 | 163 | @Override 164 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 165 | if(requestCode==Storage_Permission_code){ 166 | if(grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){ 167 | Toast.makeText(this,"Permission Granted",Toast.LENGTH_SHORT).show(); 168 | start(); 169 | }else{ 170 | Toast.makeText(this,"Permission Denied",Toast.LENGTH_SHORT).show(); 171 | 172 | } 173 | } 174 | } 175 | private void start(){ 176 | dataReading=new DataReading(this); 177 | songs=new ArrayList<>(); 178 | songs.add(new Song()); 179 | ArrayList songs = dataReading.getAllAudioFromDevice(); 180 | Collections.sort(songs); 181 | SongAdapter.songs=songs; 182 | albums=dataReading.getAlbums(); 183 | textView.setText(songs.get(0).getName()); 184 | shift(); 185 | 186 | 187 | } 188 | public void shift(){ 189 | Iterator it = albums.entrySet().iterator(); 190 | while (it.hasNext()) { 191 | Map.Entry pair = (Map.Entry)it.next(); 192 | al.add((ArrayList) pair.getValue()); 193 | it.remove(); // avoids a ConcurrentModificationException 194 | } 195 | 196 | } 197 | 198 | @Override 199 | public boolean onCreateOptionsMenu(Menu menu) { 200 | MenuInflater inflater=getMenuInflater(); 201 | inflater.inflate(R.menu.search_menu,menu); 202 | 203 | MenuItem searchItem=menu.findItem(R.id.action_search); 204 | 205 | SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); 206 | searchView.setImeOptions(EditorInfo.IME_ACTION_DONE); 207 | searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 208 | @Override 209 | public boolean onQueryTextSubmit(String query) { 210 | return false; 211 | } 212 | 213 | @Override 214 | public boolean onQueryTextChange(String newText) { 215 | SongsFragment.search(newText); 216 | return false; 217 | } 218 | }); 219 | return true; 220 | } 221 | 222 | public void sendOnChannel(String name,String artist,int position) { 223 | 224 | Intent activityIntent = new Intent(this, MainActivity.class); 225 | PendingIntent contentIntent = PendingIntent.getActivity(this, 226 | 0, activityIntent, 0); 227 | 228 | int plaorpa; 229 | if(PlayerActivity.playin){ 230 | plaorpa=R.drawable.pause_24dp; 231 | }else{ 232 | plaorpa=R.drawable.play_arrow_24dp; 233 | } 234 | metadataRetriever = new MediaMetadataRetriever(); 235 | metadataRetriever.setDataSource(songs.get(position).getPath()); 236 | arts= metadataRetriever.getEmbeddedPicture(); 237 | Bitmap artwork; 238 | try { 239 | artwork=BitmapFactory.decodeByteArray(arts,0,arts.length); 240 | }catch (Exception e){ 241 | artwork = BitmapFactory.decodeResource(getResources(), R.drawable.track_2); 242 | } 243 | notification = new NotificationCompat.Builder(this, channel_1_ID) 244 | .setSmallIcon(R.drawable.music_note_24dp) 245 | .setContentTitle(name) 246 | .setContentText("Song") 247 | .setLargeIcon(artwork) 248 | .addAction(R.drawable.previous_24dp, "Previous", playbackAction(3)) 249 | .addAction(plaorpa, "Pause", playbackAction(1)) 250 | .addAction(R.drawable.next_24dp, "Next", playbackAction(2)) 251 | .setContentIntent(contentIntent) 252 | .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle() 253 | .setShowActionsInCompactView(0, 1, 2) 254 | .setMediaSession(mediaSession.getSessionToken())) 255 | .setSubText(artist) 256 | .setPriority(NotificationCompat.PRIORITY_DEFAULT) 257 | .build(); 258 | 259 | 260 | notificationManager.notify(1, notification); 261 | } 262 | 263 | 264 | private PendingIntent playbackAction(int actionNumber) { 265 | Intent playbackAction = new Intent(this, NotiService.class); 266 | switch (actionNumber) { 267 | case 1: 268 | // Pause 269 | playbackAction.setAction("com.mypackage.ACTION_PAUSE_MUSIC"); 270 | return PendingIntent.getService(this, actionNumber, playbackAction, 0); 271 | case 2: 272 | // Next track 273 | playbackAction.setAction("com.mypackage.ACTION_NEXT_MUSIC"); 274 | return PendingIntent.getService(this, actionNumber, playbackAction, 0); 275 | case 3: 276 | // Previous track 277 | playbackAction.setAction("com.mypackage.ACTION_PREV_MUSIC"); 278 | return PendingIntent.getService(this, actionNumber, playbackAction, 0); 279 | default: 280 | break; 281 | } 282 | return null; 283 | } 284 | 285 | 286 | 287 | 288 | 289 | } 290 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mediaplayer/activities/PlayerActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mediaplayer.activities; 2 | import android.annotation.SuppressLint; 3 | import android.content.ContentUris; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Color; 7 | import android.graphics.drawable.BitmapDrawable; 8 | import android.graphics.drawable.Drawable; 9 | import android.media.MediaPlayer; 10 | import android.net.Uri; 11 | import android.os.Handler; 12 | import android.os.Message; 13 | import android.preference.PreferenceManager; 14 | import android.support.annotation.Nullable; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.os.Bundle; 17 | import android.support.v7.graphics.Palette; 18 | import android.view.View; 19 | import android.widget.ImageView; 20 | import android.widget.LinearLayout; 21 | import android.widget.SeekBar; 22 | import android.widget.TextView; 23 | import com.bumptech.glide.Glide; 24 | import com.bumptech.glide.load.DataSource; 25 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 26 | import com.bumptech.glide.load.engine.GlideException; 27 | import com.bumptech.glide.request.RequestListener; 28 | import com.bumptech.glide.request.target.Target; 29 | import com.example.mediaplayer.adapters.SongAdapter; 30 | import com.example.mediaplayer.adapters.SongAlbumAdapter; 31 | import com.example.mediaplayer.models.Song; 32 | import com.example.mediaplayer.notification.NofiticationCenter; 33 | import com.example.mediaplayer.R; 34 | import java.util.ArrayList; 35 | import java.util.Collections; 36 | public class PlayerActivity extends AppCompatActivity { 37 | 38 | 39 | 40 | public static boolean playin; 41 | private ArrayListAsongs; 42 | private static SeekBar mSeekBar; 43 | private static PlayerActivity instance; 44 | int position; 45 | private static TextView curTime,totTime; 46 | private TextView songTitle,artistname; 47 | private static ImageView pause,prev,next; 48 | private ImageView imageView; 49 | protected int val; 50 | protected boolean place; 51 | private Palette.Swatch DarkVibrantSwatch; 52 | private Palette.Swatch darkMutedSwatch; 53 | 54 | 55 | protected NofiticationCenter nofiticationCenter; 56 | protected LinearLayout linearLayout,linear1; 57 | private static MediaPlayer mMediaPlayer; 58 | 59 | public int getPosition() { 60 | return position; 61 | } 62 | 63 | 64 | public void setPosition(int position) { 65 | this.position = position; 66 | } 67 | 68 | @Override 69 | protected void onCreate(Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | setContentView(R.layout.activity_player); 72 | nofiticationCenter = new NofiticationCenter(); 73 | mSeekBar = findViewById(R.id.seek); 74 | songTitle = findViewById(R.id.song_name); 75 | artistname = findViewById(R.id.artist_name); 76 | totTime = findViewById(R.id.total_time); 77 | pause = findViewById(R.id.pause); 78 | linearLayout = findViewById(R.id.linear_layout); 79 | prev = findViewById(R.id.previous); 80 | next = findViewById(R.id.next); 81 | curTime = findViewById(R.id.current_time); 82 | imageView = findViewById(R.id.imageplayer); 83 | linear1=findViewById(R.id.linear1); 84 | Intent i = getIntent(); 85 | Bundle bundle = i.getExtras(); 86 | position = bundle.getInt("index"); 87 | val = bundle.getInt("val"); 88 | place = bundle.getBoolean("from"); 89 | if(instance!=null&&place==false){ 90 | songTitle.setText(instance.songTitle.getText()); 91 | artistname.setText(instance.artistname.getText()); 92 | totTime.setText(instance.totTime.getText()); 93 | curTime.setText(instance.curTime.getText()); 94 | imageView.setImageDrawable(instance.imageView.getDrawable()); 95 | initiateSeekBar(); 96 | Asongs=instance.Asongs; 97 | position=instance.position; 98 | setBackground(); 99 | }else { 100 | if (mMediaPlayer != null) { 101 | mMediaPlayer.stop(); 102 | } 103 | instance = this; 104 | if (val == 1) { 105 | Asongs = SongAlbumAdapter.albumSong; 106 | } else if (val == 2) { 107 | Asongs = SongAdapter.songs; 108 | Collections.shuffle(Asongs); 109 | } else { 110 | Asongs = SongAdapter.songs; 111 | } 112 | if (Asongs.get(position).getName() == "shufflee") 113 | position = (position + 1) % Asongs.size(); 114 | initPlayer(position); 115 | MainActivity.imageView.setBackgroundResource(R.drawable.pause_24dp); 116 | } 117 | Buttons(); 118 | 119 | 120 | } 121 | 122 | public static PlayerActivity getInstance() { 123 | return instance; 124 | } 125 | 126 | 127 | public void setData(int position){ 128 | 129 | String name= Asongs.get(position).getName(); 130 | String artist= Asongs.get(position).getArtist(); 131 | songTitle.setText(name); 132 | artistname.setText(artist); 133 | MainActivity.getInstance().textView.setText(name); 134 | try { 135 | 136 | Glide 137 | .with(getApplicationContext()) 138 | .load(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"),Asongs.get(position).getAlbumID()).toString()) 139 | .thumbnail(0.2f) 140 | .centerCrop() 141 | .placeholder(R.drawable.track) 142 | .skipMemoryCache(true) 143 | .diskCacheStrategy(DiskCacheStrategy.NONE) 144 | .listener(new RequestListener() { 145 | @Override 146 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { 147 | return false; 148 | } 149 | 150 | @Override 151 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { 152 | setBackground(); 153 | return false; 154 | } 155 | }) 156 | .into(imageView); 157 | } 158 | catch (Exception e){ 159 | 160 | Glide.with(this).load(R.drawable.track).into(imageView); 161 | } 162 | 163 | 164 | } 165 | 166 | public static void initiateSeekBar(){ 167 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 168 | @Override 169 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 170 | if (fromUser) { 171 | mMediaPlayer.seekTo(progress*1000); 172 | } 173 | 174 | } 175 | 176 | @Override 177 | public void onStartTrackingTouch(SeekBar seekBar) { 178 | 179 | } 180 | 181 | @Override 182 | public void onStopTrackingTouch(SeekBar seekBar) { 183 | 184 | } 185 | }); 186 | } 187 | 188 | public void Buttons(){ 189 | pause.setOnClickListener(new View.OnClickListener() { 190 | @Override 191 | public void onClick(View v) { 192 | play(); 193 | } 194 | }); 195 | prev.setOnClickListener(new View.OnClickListener() { 196 | @Override 197 | public void onClick(View v) { 198 | 199 | if (position == 0) { 200 | position = Asongs.size() - 1; 201 | } else { 202 | position--; 203 | } 204 | initPlayer(position); 205 | 206 | } 207 | }); 208 | 209 | next.setOnClickListener(new View.OnClickListener() { 210 | @Override 211 | public void onClick(View v) { 212 | position=(position+1)% Asongs.size(); 213 | initPlayer(position); 214 | } 215 | }); 216 | } 217 | 218 | public void initPlayer(final int position) { 219 | 220 | playin=true; 221 | if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { 222 | mMediaPlayer.reset(); 223 | } 224 | String name= Asongs.get(position).getName(); 225 | String artist= Asongs.get(position).getArtist(); 226 | setData(position); 227 | MainActivity.getInstance().sendOnChannel(name,artist,position); 228 | 229 | 230 | mMediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(Asongs.get(position).getPath())); // create and load mediaplayer with song resources 231 | mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 232 | @Override 233 | public void onPrepared(MediaPlayer mp) { 234 | String totalTime = createTimeLabel(mMediaPlayer.getDuration()); 235 | totTime.setText(totalTime); 236 | mSeekBar.setMax(mMediaPlayer.getDuration()/1000 ); 237 | mMediaPlayer.start(); 238 | pause.setBackgroundResource(R.drawable.pause_24dp); 239 | 240 | } 241 | }); 242 | 243 | mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 244 | @Override 245 | public void onCompletion(MediaPlayer mp) { 246 | int curSongPoition = position; 247 | curSongPoition = (curSongPoition + 1) % (Asongs.size()); 248 | initPlayer(curSongPoition); 249 | 250 | } 251 | }); 252 | initiateSeekBar(); 253 | 254 | 255 | new Thread(new Runnable() { 256 | @Override 257 | public void run() { 258 | while (mMediaPlayer != null) { 259 | try { 260 | if (mMediaPlayer.isPlaying()) { 261 | Message msg = new Message(); 262 | msg.what = mMediaPlayer.getCurrentPosition(); 263 | msg.arg1=mMediaPlayer.getDuration(); 264 | handler.sendMessage(msg); 265 | Thread.sleep(1000); 266 | } 267 | } catch (InterruptedException e) { 268 | e.printStackTrace(); 269 | } 270 | } 271 | } 272 | }).start(); 273 | } 274 | 275 | @SuppressLint("HandlerLeak") 276 | private Handler handler = new Handler() { 277 | @Override 278 | public void handleMessage(Message msg) { 279 | int current_position = msg.what; 280 | mSeekBar.setMax(mMediaPlayer.getDuration()/1000); 281 | mSeekBar.setProgress(current_position/1000); 282 | System.out.println(mSeekBar.getProgress()); 283 | String cTime = createTimeLabel(current_position); 284 | curTime.setText(cTime); 285 | totTime.setText(createTimeLabel(msg.arg1)); 286 | } 287 | }; 288 | public void play() { 289 | 290 | if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) { 291 | playin=true; 292 | mMediaPlayer.start(); 293 | pause.setBackgroundResource(R.drawable.pause_24dp); 294 | MainActivity.getInstance().sendOnChannel( Asongs.get(position).getName(), Asongs.get(position).getArtist(),position); 295 | MainActivity.imageView.setBackgroundResource(R.drawable.pause_24dp); 296 | } else { 297 | pause(); 298 | } 299 | 300 | } 301 | 302 | public void pause() { 303 | if (mMediaPlayer.isPlaying()) { 304 | playin=false; 305 | mMediaPlayer.pause(); 306 | pause.setBackgroundResource(R.drawable.play_arrow_24dp); 307 | MainActivity.getInstance().sendOnChannel( Asongs.get(position).getName(), Asongs.get(position).getArtist(),position); 308 | MainActivity.imageView.setBackgroundResource(R.drawable.play_arrow_24dp); 309 | } 310 | 311 | } 312 | 313 | 314 | public String createTimeLabel(int duration) { 315 | String timeLabel = ""; 316 | int min = duration / 1000 / 60; 317 | int sec = duration / 1000 % 60; 318 | 319 | timeLabel += min + ":"; 320 | if (sec < 10) timeLabel += "0"; 321 | timeLabel += sec; 322 | 323 | return timeLabel; 324 | 325 | 326 | } 327 | public void setBackground(){ 328 | Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); 329 | 330 | Palette.from(bitmap).maximumColorCount(32).generate(new Palette.PaletteAsyncListener() { 331 | @Override 332 | public void onGenerated(Palette palette) { 333 | DarkVibrantSwatch = palette.getDarkVibrantSwatch(); 334 | darkMutedSwatch = palette.getDarkMutedSwatch(); 335 | if (DarkVibrantSwatch!= null) { 336 | linearLayout.setBackgroundColor( DarkVibrantSwatch.getRgb()); 337 | linear1.setBackgroundColor( DarkVibrantSwatch.getRgb()); 338 | 339 | } else { 340 | linearLayout.setBackgroundColor(getResources().getColor(R.color.colorAccent)); 341 | linear1.setBackgroundColor(getResources().getColor(R.color.colorAccent)); 342 | 343 | } 344 | } 345 | }); 346 | } 347 | 348 | public static boolean isPlayin() { 349 | return playin; 350 | } 351 | } --------------------------------------------------------------------------------