├── README.txt
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── style.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── mpl.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ ├── background.png
│ │ │ │ ├── background1.png
│ │ │ │ ├── background2.png
│ │ │ │ └── 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-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── layout
│ │ │ │ ├── divider.xml
│ │ │ │ ├── activity_audio_recorder.xml
│ │ │ │ ├── songinfo.xml
│ │ │ │ ├── forvolume.xml
│ │ │ │ ├── content_audio_recorder.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── list
│ │ │ └── deepakpawate
│ │ │ └── playmusic
│ │ │ ├── storesong.java
│ │ │ ├── VolumeActivity.java
│ │ │ ├── AudioRecorderActivity.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── list
│ │ │ └── deepakpawate
│ │ │ └── playmusic
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── list
│ │ └── deepakpawate
│ │ └── playmusic
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── local.properties
├── README.md
├── PlayMusic.iml
├── gradle.properties
├── gradlew.bat
└── gradlew
/README.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/mpl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xxhdpi/mpl.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/drawable/background.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/drawable/background1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/drawable/background2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/intel/android-apps/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/divider.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Music App
3 | Lvol
4 | HVol
5 | AudioRecorderActivity
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 18 07:46:16 IST 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/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/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file should *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=C\:\\Users\\dpawate\\AppData\\Local\\Android\\Sdk
--------------------------------------------------------------------------------
/app/src/test/java/com/example/list/deepakpawate/playmusic/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DISCONTINUATION OF PROJECT
2 |
3 | This project will no longer be maintained by Intel.
4 |
5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.
6 |
7 | Intel no longer accepts patches to this project.
8 |
9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project.
10 |
11 | Contact: webadmin@linux.intel.com
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1e041c
4 | #9f4630
5 | #51309f
6 | #ffb700
7 | #ffffff
8 | #00000000
9 | #000000
10 | #999999
11 | #0066cc
12 | #f1f17a
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/PlayMusic.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/list/deepakpawate/playmusic/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
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 org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.list.deepakpawate.playmusic", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Tue Apr 09 10:31:31 IST 2019
16 | systemProp.http.proxyPassword=Veena2018\!
17 | systemProp.http.proxyHost=proxy.iind.intel.com
18 | systemProp.http.nonProxyHosts=proxy.iind.intel.com
19 | org.gradle.jvmargs=-Xmx1536m
20 | systemProp.http.proxyUser=dpawate
21 | systemProp.http.proxyPort=911
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.example.list.deepakpawate.playmusic"
7 | minSdkVersion 15
8 | targetSdkVersion 26
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.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | implementation 'com.android.support:design:26.1.0'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29 | implementation 'com.android.support:cardview-v7:26+'
30 | implementation 'com.android.support:support-annotations:27.1.1'
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_audio_recorder.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/songinfo.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
15 |
20 |
21 |
22 |
34 |
35 |
45 |
46 |
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/res/layout/forvolume.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
25 |
26 |
37 |
38 |
47 |
48 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/list/deepakpawate/playmusic/storesong.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.media.MediaMetadataRetriever;
6 | import android.provider.MediaStore;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.SimpleCursorAdapter;
12 | import android.widget.TextView;
13 |
14 | import java.math.BigDecimal;
15 |
16 | /**
17 | * Created by dpawate on 3/18/2018.
18 | */
19 |
20 |
21 | public class storesong extends SimpleCursorAdapter {
22 | public storesong(Context context, int layout, Cursor c) {
23 | super(context, layout, c, new String[]{MediaStore.MediaColumns.DISPLAY_NAME,
24 | MediaStore.MediaColumns.TITLE,MediaStore.Audio.AudioColumns.DURATION},
25 | new int[]{R.id.title, R.id.duration});
26 | }
27 |
28 | @Override
29 | public void bindView(View view, Context context, Cursor cursor) {
30 | TextView title = (TextView) view.findViewById(R.id.title);
31 | TextView duration = (TextView) view.findViewById(R.id.duration);
32 | String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
33 | if (data.contains("aac")) {
34 | Log.e("Mimetype",data);
35 | }
36 | title.setText(cursor.getString(cursor.getColumnIndex(
37 | MediaStore.MediaColumns.TITLE)));
38 | String str =cursor.getString(cursor.getColumnIndex(
39 | MediaStore.MediaColumns.MIME_TYPE));
40 | Log.e("Mime type",str);
41 | long durationInMilli = Long.parseLong(cursor.getString(
42 | cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION)));
43 |
44 | double durationInMinutes = ((double) durationInMilli / 1000.0) / 60.0;
45 | durationInMinutes = new BigDecimal(Double.toString(durationInMinutes)).
46 | setScale(2, BigDecimal.ROUND_UP).doubleValue();
47 | duration.setText("" + durationInMinutes);
48 | view.setTag(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)));
49 | }
50 |
51 | @Override
52 | public View newView(Context context, Cursor cursor, ViewGroup parent) {
53 | LayoutInflater inflater = LayoutInflater.from(context);
54 | View v = inflater.inflate(R.layout.songinfo, parent, false);
55 | Log.e("b4","bindView");
56 | Log.e("b4","#################################");
57 | bindView(v, context, cursor);
58 | return v;
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_audio_recorder.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
24 |
25 |
34 |
35 |
50 |
51 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
15 |
22 |
23 |
29 |
36 |
37 |
46 |
47 |
56 |
57 |
63 |
64 |
69 |
70 |
75 |
76 |
81 |
82 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/list/deepakpawate/playmusic/VolumeActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
2 |
3 | import android.app.DatePickerDialog;
4 | import android.content.Intent;
5 | import android.media.AudioManager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.CheckBox;
12 | import android.widget.CompoundButton;
13 | import android.widget.SeekBar;
14 | import android.widget.Switch;
15 | import android.widget.Toast;
16 |
17 | import static android.media.AudioManager.STREAM_MUSIC;
18 | import static com.example.list.deepakpawate.playmusic.MainActivity.audioManager;
19 | import static com.example.list.deepakpawate.playmusic.MainActivity.player;
20 |
21 |
22 | public class VolumeActivity extends AppCompatActivity {
23 | SeekBar setVolume;
24 | private CheckBox checkBox;
25 | private float gvolume;
26 | private Switch gswitch;
27 | private Button buttonVar;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.forvolume);
33 | setVolume = (SeekBar) findViewById(R.id.seekBar2);
34 | checkBox = (CheckBox) findViewById(R.id.checkBox);
35 | gswitch =(Switch) findViewById(R.id.switch1) ;
36 | buttonVar =(Button) findViewById(R.id.button) ;
37 | setVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
38 | @Override
39 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
40 | Log.e("volume bar", "inside volume bar");
41 | float volumeNum = progress / 100f;
42 | gvolume = volumeNum;
43 | Log.e("volume bar", "inside volume bar" + gvolume);
44 | player.setVolume(volumeNum, volumeNum);
45 | }
46 |
47 | @Override
48 | public void onStartTrackingTouch(SeekBar seekBar) {
49 |
50 | }
51 |
52 | @Override
53 | public void onStopTrackingTouch(SeekBar seekBar) {
54 |
55 | }
56 | }
57 | );
58 | checkBox.setOnClickListener(new View.OnClickListener() {
59 |
60 |
61 | @Override
62 | public void onClick(View v) {
63 | switch (v.getId()) {
64 | case R.id.checkBox: {
65 | if (((CheckBox) v).isChecked()) {
66 | Log.e("check volume", "global volume" + gvolume);
67 | Log.e("Mute pressed", "change volume");
68 | player.setVolume(0, 0);
69 | } else {
70 | Log.e("Mute unpressed", "change volume");
71 | Log.e("unpressed mute", "global volume" + gvolume);
72 | player.setVolume((float)0.8, (float)0.8);
73 | }
74 | }
75 | }
76 | }
77 | });
78 |
79 | gswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
80 | @Override
81 | public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
82 | if(b == true) {
83 | Intent intent = new Intent(VolumeActivity.this, AudioRecorderActivity.class);
84 | Log.d("gswitch", "gswitch true: ");
85 | startActivity(intent);
86 | gswitch.setChecked(false);
87 |
88 | }
89 | }
90 | });
91 |
92 | buttonVar.setOnClickListener(new View.OnClickListener() {
93 | @Override
94 | public void onClick(View view) {
95 | Log.e("buttonVar", "buttonVar.setOnClickListener: ");
96 | finish();
97 | }
98 | });
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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/list/deepakpawate/playmusic/AudioRecorderActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
2 |
3 | import android.Manifest;
4 | import android.content.pm.PackageManager;
5 | import android.media.MediaPlayer;
6 | import android.media.MediaRecorder;
7 | import android.os.Bundle;
8 | import android.os.Environment;
9 | import android.support.design.widget.FloatingActionButton;
10 | import android.support.design.widget.Snackbar;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v4.content.ContextCompat;
13 | import android.support.v7.app.AppCompatActivity;
14 | import android.support.v7.widget.Toolbar;
15 | import android.util.Log;
16 | import android.view.View;
17 | import android.widget.Button;
18 | import android.widget.Toast;
19 |
20 | import java.io.IOException;
21 |
22 | public class AudioRecorderActivity extends AppCompatActivity {
23 |
24 | private Button startR1 = null, stopR2 = null, playR3 = null;
25 | public static final int RequestPermissionCode = 101;
26 | String filePath = null;
27 | String fileName = "recordedFile.mp4";
28 | MediaRecorder audioRecorder;
29 | MediaPlayer audioPlayer;
30 | Button buttonVar3;
31 | private boolean recNotStarted = false;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_audio_recorder);
37 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
38 | setSupportActionBar(toolbar);
39 |
40 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
41 | fab.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View view) {
44 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
45 | .setAction("Action", null).show();
46 | }
47 | });
48 |
49 | startR1 = (Button) findViewById(R.id.startR);
50 | stopR2 = (Button) findViewById(R.id.stopR);
51 | playR3 = (Button) findViewById(R.id.playR);
52 | buttonVar3 =(Button) findViewById(R.id.button3) ;
53 | playR3.setEnabled(false);
54 | stopR2.setEnabled(false);
55 |
56 | startR1.setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View view) {
59 | Log.e(" Rec_file", "startR1.setOnClickListener: ");
60 | Log.e("startR", "onClick: ");
61 | playR3.setEnabled(false);
62 | recordAudioFromMic();
63 | }
64 | });
65 |
66 | stopR2.setOnClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View view) {
69 | Log.e(" Rec_file ", "stopR2.setOnClickListener: ");
70 | Log.e("stopR", "onClick: ");
71 | stopRecording();
72 | }
73 | });
74 |
75 | playR3.setOnClickListener(new View.OnClickListener() {
76 | @Override
77 | public void onClick(View view) {
78 | Log.e(" Rec_file ", "playR3.setOnClickListener: ");
79 | playRecorded();
80 | }
81 | });
82 |
83 | buttonVar3.setOnClickListener(new View.OnClickListener() {
84 | @Override
85 | public void onClick(View view) {
86 | Log.e("AudioRecorder", "buttonVar.setOnClickListener: ");
87 | finish();
88 | }
89 | });
90 |
91 | }
92 |
93 |
94 | public boolean createRecOutputFile() {
95 | boolean file;
96 | filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"
97 | + "recordedFile.mp4";
98 | Log.e(" Rec_file", "createRecOutputFile: " + filePath);
99 | if (filePath != null && !filePath.isEmpty())
100 | return true;
101 |
102 | return false;
103 | }
104 |
105 | public void configure() {
106 | audioRecorder = new MediaRecorder();
107 | audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
108 | audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
109 | audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
110 | audioRecorder.setOutputFile(filePath);
111 | }
112 |
113 | public void recordAudioFromMic() {
114 | Log.e(" Rec_file [1]", "recordAudioFromMic: ");
115 | if (checkPermission()) {
116 | Log.e(" Rec_file [2]", "recordAudioFromMic: ");
117 | if (createRecOutputFile()) {
118 | Log.e(" Rec_file [3]", "recordAudioFromMic: " + filePath);
119 | configure();
120 | Log.e(" Rec_file [4]", "recordAudioFromMic: " + filePath);
121 |
122 | try {
123 | audioRecorder.prepare();
124 | audioRecorder.start();
125 | } catch (IllegalStateException e) {
126 |
127 | e.printStackTrace();
128 | } catch (IOException e) {
129 |
130 | e.printStackTrace();
131 | }
132 | startR1.setEnabled(false);
133 | stopR2.setEnabled(true);
134 | recNotStarted = true;
135 | }
136 | }else {
137 | Log.e("Rec_File", "needPermission: ");
138 | needPermission();
139 | }
140 | }
141 |
142 | public void needPermission() {
143 | Log.e("Rec_File", "inside needPermission: ");
144 | ActivityCompat.requestPermissions(AudioRecorderActivity.this, new
145 | String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, RequestPermissionCode);
146 | }
147 |
148 | @Override
149 | public void onRequestPermissionsResult(int requestCode,
150 | String permissions[], int[] grantResults) {
151 | Log.e("Rec_file", "onRequestPermissionsResult: ");
152 | switch (requestCode) {
153 | case RequestPermissionCode:
154 | if (grantResults.length > 0) {
155 | boolean StoragePermission = grantResults[0] ==
156 | PackageManager.PERMISSION_GRANTED;
157 | boolean RecordPermission = grantResults[1] ==
158 | PackageManager.PERMISSION_GRANTED;
159 |
160 | if (StoragePermission && RecordPermission) {
161 | Toast.makeText(AudioRecorderActivity.this, "Permission Granted",
162 | Toast.LENGTH_LONG).show();
163 | } else {
164 | Toast.makeText(AudioRecorderActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
165 | }
166 | }
167 | break;
168 | }
169 | }
170 |
171 | public boolean checkPermission() {
172 | Log.e("Rec_file", "checkPermission: ");
173 | int recAudioPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
174 | int writeExt = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
175 |
176 | return recAudioPermission == PackageManager.PERMISSION_GRANTED &&
177 | writeExt == PackageManager.PERMISSION_GRANTED;
178 | }
179 |
180 | public void playRecorded() {
181 | Log.e("check boolean", "playRecorded: " + MainActivity.player.isPlaying());
182 | if(MainActivity.player.isPlaying()){
183 | Log.e("Pausing Main Player", "playRecorded()");
184 | MainActivity.player.pause();
185 | MainActivity.play.setImageResource(android.R.drawable.ic_media_play);
186 | }
187 | stopR2.setEnabled(false);
188 | audioPlayer = new MediaPlayer();
189 | try {
190 | audioPlayer.setDataSource(filePath);
191 | audioPlayer.prepare();
192 | } catch (IOException e) {
193 | e.printStackTrace();
194 | }
195 |
196 | audioPlayer.start();
197 | }
198 |
199 | public void stopRecording() {
200 | if(!recNotStarted) {
201 | Toast.makeText(AudioRecorderActivity.this, "Record before stop recording",
202 | Toast.LENGTH_SHORT).show();
203 | return;
204 | }
205 | audioRecorder.stop();
206 | stopR2.setEnabled(false);
207 | playR3.setEnabled(true);
208 | startR1.setEnabled(true);
209 | recNotStarted = false;
210 | }
211 |
212 | }
213 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/list/deepakpawate/playmusic/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.list.deepakpawate.playmusic;
2 |
3 | import android.content.ContentResolver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.media.AudioManager;
7 | import android.media.Ringtone;
8 | import android.media.audiofx.Equalizer;
9 | import android.webkit.MimeTypeMap;
10 | import android.widget.ImageButton;
11 | import android.widget.ListView;
12 | import android.widget.SeekBar;
13 | import android.widget.TextView;
14 | import android.Manifest;
15 | import android.content.pm.PackageManager;
16 | import android.support.v4.app.ActivityCompat;
17 | import android.support.v4.content.ContextCompat;
18 | import android.support.v7.app.AppCompatActivity;
19 | import android.os.Bundle;
20 | import android.app.ListActivity;
21 | import android.database.Cursor;
22 | import android.media.MediaPlayer;
23 | import android.os.Bundle;
24 | import android.os.Handler;
25 | import java.io.IOException;
26 | import java.util.List;
27 | import android.provider.MediaStore.Audio.Albums;
28 | import android.provider.MediaStore;
29 | import android.util.Log;
30 | import android.view.View;
31 | import android.view.ViewGroup;
32 | import android.widget.Toast;
33 |
34 | public class MainActivity extends ListActivity {
35 | private static final int FREQUENCY = 500;
36 | private static final int PEMISSION_NUMBER = 2;
37 | private static final int STEP_VALUE = 4000;
38 | private TextView selectedfile = null;
39 | private SeekBar seekBar = null;
40 | public static MediaPlayer player = null;
41 | public static String durationMin;
42 | public static Equalizer eq_var = null;
43 | public static AudioManager audioManager;
44 | private ImageButton prev = null;
45 | public static ImageButton play = null;
46 | private ImageButton next = null;
47 | private ImageButton volume = null;
48 |
49 | private storesong adapter = null;
50 | private ListView lv = null;
51 | private ListView m_listView = null;
52 | private int m_position;
53 | private int number_of_list_items;
54 |
55 | private boolean isStarted = true;
56 | private String currentFile = "";
57 | private boolean isMovingSeekBar = false;
58 | private final Handler handler = new Handler();
59 |
60 |
61 | private final Runnable updateSeekBarRunnable = new Runnable() {
62 | @Override
63 | public void run() {
64 | setSongProgress();
65 | }
66 | };
67 |
68 | @Override
69 | protected void onCreate(Bundle savedInstanceState) {
70 | super.onCreate(savedInstanceState);
71 | // Very imp this is the first thing to do
72 | setContentView(R.layout.activity_main);
73 | if (ContextCompat.checkSelfPermission(this,
74 | Manifest.permission.READ_EXTERNAL_STORAGE)
75 | != PackageManager.PERMISSION_GRANTED) {
76 | if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
77 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PEMISSION_NUMBER);
78 | } else {
79 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PEMISSION_NUMBER);
80 | }
81 | } else {
82 | // Start creating the user interface
83 | Log.e("b4", "createplayer" + currentFile);
84 | createplayer();
85 | }
86 |
87 | }
88 |
89 | public void createplayer() {
90 | selectedfile = (TextView) findViewById(R.id.selecteditem);
91 | seekBar = (SeekBar) findViewById(R.id.seekBar);
92 | prev = (ImageButton) findViewById(R.id.previous);
93 | play = (ImageButton) findViewById(R.id.play);
94 | next = (ImageButton) findViewById(R.id.next);
95 | volume = (ImageButton) findViewById(R.id.volume);
96 | player = new MediaPlayer();
97 | player.setOnCompletionListener(onCompletion);
98 | player.setOnErrorListener(onError);
99 | seekBar.setOnSeekBarChangeListener(seekBarChanged);
100 |
101 | Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.Media.IS_MUSIC, null, null);
102 |
103 | if (null != cursor) {
104 | cursor.moveToFirst();
105 | adapter = new storesong(this, R.layout.songinfo, cursor);
106 | setListAdapter(adapter);
107 |
108 | number_of_list_items = getListAdapter().getCount();
109 | Log.e("number of list items", "number_of_list_items =" + number_of_list_items);
110 | prev.setOnClickListener(OnButtonClick);
111 | play.setOnClickListener(OnButtonClick);
112 | next.setOnClickListener(OnButtonClick);
113 | volume.setOnClickListener(OnButtonClick);
114 | Log.e("setOnClickListener", "b4 button press" + currentFile);
115 | }
116 | }
117 |
118 | @Override
119 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
120 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
121 |
122 | switch (requestCode) {
123 | case PEMISSION_NUMBER: {
124 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
125 | if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) == (PackageManager.PERMISSION_GRANTED)) {
126 | createplayer();
127 | Log.e("createplayer called", "createplayer called");
128 | }
129 | } else {
130 | Log.e("Permission required", "Permission required");
131 | }
132 | return;
133 | }
134 | }
135 | }
136 |
137 | @Override
138 | protected void onListItemClick(ListView l, View v, int position, long id) {
139 | super.onListItemClick(l, v, position, id);
140 | //View inflatedView = getLayoutInflater().inflate(R.layout.songinfo, null);
141 | m_position = position;
142 | Log.e("song position", "song position" + m_position + "v.getTag =" + v.getTag());
143 | currentFile = (String) v.getTag();
144 | TextView duration = v.findViewById(R.id.duration);
145 | durationMin = (String)duration.getText();
146 | m_listView = l;
147 | startPlay(currentFile);
148 | }
149 |
150 | private String getViewTag(int position) {
151 | View view = m_listView.getAdapter().getView(position, null, m_listView);
152 | String songString = (String) view.getTag();
153 |
154 | return songString;
155 | }
156 |
157 | private void startPlay(String file) {
158 | Log.e("Selected: ", file);
159 |
160 | //Use this selectedfile.setText(file) to get the song name
161 | //selectedfile.setText(file + " T = " + durationMin);
162 | selectedfile.setText(file);
163 | seekBar.setProgress(0);
164 | player.stop();
165 | player.reset();
166 |
167 | try {
168 | player.setDataSource(file);
169 | player.prepare();
170 | player.start();
171 | Log.e("Session ID", "startPlay: " + player.getAudioSessionId());
172 | Log.e("set Eq", "enabled Equilizer");
173 | } catch (IllegalArgumentException e) {
174 | e.printStackTrace();
175 | } catch (IllegalStateException e) {
176 | e.printStackTrace();
177 | } catch (IOException e) {
178 | e.printStackTrace();
179 | }
180 | seekBar.setMax(player.getDuration());
181 | play.setImageResource(android.R.drawable.ic_media_pause);
182 | setSongProgress();
183 | isStarted = true;
184 | }
185 |
186 | private void stopPlay() {
187 | player.stop();
188 | player.reset();
189 | play.setImageResource(android.R.drawable.ic_media_play);
190 | handler.removeCallbacks(updateSeekBarRunnable);
191 | seekBar.setProgress(0);
192 | isStarted = false;
193 | }
194 |
195 | @Override
196 | protected void onDestroy() {
197 | super.onDestroy();
198 | handler.removeCallbacks(updateSeekBarRunnable);
199 | player.stop();
200 | player.reset();
201 | player.release();
202 | player = null;
203 | }
204 |
205 | private void setSongProgress() {
206 | handler.removeCallbacks(updateSeekBarRunnable);
207 | seekBar.setProgress(player.getCurrentPosition());
208 | handler.postDelayed(updateSeekBarRunnable, FREQUENCY);
209 | }
210 |
211 | private void printCompletionSong() {
212 | //String CurrentSong = getViewTag(m_position);
213 | Log.e("########","##################");
214 | Log.e("########","##################" + m_position);
215 | }
216 |
217 | private MediaPlayer.OnCompletionListener onCompletion = new MediaPlayer.OnCompletionListener() {
218 | @Override
219 | public void onCompletion(MediaPlayer mp) {
220 |
221 | String nextSong ;
222 | ++m_position;
223 | Log.e("OnCompletionListener", "onCompletion: " + m_position + number_of_list_items);
224 | if(m_position == number_of_list_items) {
225 | m_position = 0;
226 | nextSong = getViewTag(m_position);
227 | } else {
228 | nextSong = getViewTag(m_position);
229 | }
230 | Log.e("OnCompletionListener","onCompletion" + nextSong);
231 | Log.e("song number","number =" + m_position);
232 | startPlay(nextSong);
233 | }
234 | };
235 |
236 | private MediaPlayer.OnErrorListener onError = new MediaPlayer.OnErrorListener() {
237 | @Override
238 | public boolean onError(MediaPlayer mp, int what, int extra) {
239 | return false;
240 | }
241 | };
242 |
243 | private SeekBar.OnSeekBarChangeListener seekBarChanged =
244 | new SeekBar.OnSeekBarChangeListener() {
245 | @Override
246 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
247 | if (isMovingSeekBar) {
248 | player.seekTo(progress);
249 | Log.e("OnSeekBarChangeListener", "song progressing OnProgressChanged");
250 | }
251 | }
252 |
253 | @Override
254 | public void onStartTrackingTouch(SeekBar seekBar) {
255 | isMovingSeekBar = true;
256 | }
257 |
258 | @Override
259 | public void onStopTrackingTouch(SeekBar seekBar) {
260 | isMovingSeekBar = false;
261 | }
262 | };
263 |
264 | private boolean checkFileEmpty() {
265 | if(currentFile.isEmpty()) {
266 | Log.e("File is null: ", currentFile);
267 | Toast.makeText(MainActivity.this,"Select song to start Play if NO songs then Add few",Toast.LENGTH_LONG).show();
268 | return true;
269 | }
270 | return false;
271 | }
272 |
273 |
274 | private View.OnClickListener OnButtonClick = new View.OnClickListener() {
275 | @Override
276 | public void onClick(View v) {
277 |
278 | switch (v.getId()) {
279 | case R.id.play: {
280 | if(checkFileEmpty()) {
281 | return;
282 | }
283 | Log.e("Play Button1", "Pressed" + currentFile);
284 | Log.e("Play button pressed", "which soong number =" + m_position);
285 | if (player.isPlaying()) {
286 | handler.removeCallbacks(updateSeekBarRunnable);
287 | player.pause();
288 | play.setImageResource(android.R.drawable.ic_media_play);
289 | } else {
290 | if (isStarted) {
291 | player.start();
292 | play.setImageResource(android.R.drawable.ic_media_pause);
293 | setSongProgress();
294 | } else {
295 | startPlay(currentFile);
296 | }
297 | }
298 | break;
299 | }
300 |
301 | case R.id.next: {
302 | Log.e("Next Button", "Pressed");
303 | if(checkFileEmpty()) {
304 | return;
305 | }
306 | player.pause();
307 | player.seekTo(player.getDuration());
308 |
309 | ++m_position;
310 | Log.e("Next Button", "Position onf last song" + m_position);
311 | Log.e("Next Button", "No of songs" + number_of_list_items);
312 | if(m_position == number_of_list_items) {
313 | m_position = 0;
314 | }
315 | String nextSong = getViewTag(m_position);
316 | Log.e("nextSong", "song position" + nextSong);
317 | startPlay(nextSong);
318 | break;
319 | }
320 |
321 | case R.id.previous: {
322 | Log.e("Previous Button", "Pressed");
323 | if(checkFileEmpty()) {
324 | return;
325 | }
326 | player.pause();
327 | player.seekTo(player.getCurrentPosition());
328 | --m_position;
329 | String nextSong = getViewTag(m_position);
330 | Log.e("nextSong", "song position" + nextSong);
331 | startPlay(nextSong);
332 | break;
333 | }
334 |
335 | case R.id.volume: {
336 | Log.e("volume pressed", "change volume");
337 | Intent intent = new Intent(MainActivity.this, VolumeActivity.class);
338 | startActivity(intent);
339 | break;
340 | }
341 | }
342 | }
343 | };
344 |
345 |
346 | }
347 |
--------------------------------------------------------------------------------