├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── base ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mobile │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── android │ │ │ └── musicplayercodelab │ │ │ ├── MediaItemViewHolder.java │ │ │ ├── MusicLibrary.java │ │ │ ├── MusicPlayerActivity.java │ │ │ └── PlaybackManager.java │ │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_equalizer1_white_36dp.png │ │ ├── ic_equalizer2_white_36dp.png │ │ ├── ic_equalizer3_white_36dp.png │ │ ├── ic_launcher.png │ │ ├── ic_notification.png │ │ ├── ic_pause_black_36dp.png │ │ ├── ic_pause_white_24dp.png │ │ ├── ic_play_arrow_black_36dp.png │ │ ├── ic_play_arrow_white_24dp.png │ │ ├── ic_skip_next_white_24dp.png │ │ └── ic_skip_previous_white_24dp.png │ │ ├── drawable-mdpi │ │ ├── ic_equalizer1_white_36dp.png │ │ ├── ic_equalizer2_white_36dp.png │ │ ├── ic_equalizer3_white_36dp.png │ │ ├── ic_launcher.png │ │ ├── ic_notification.png │ │ ├── ic_pause_black_36dp.png │ │ ├── ic_pause_white_24dp.png │ │ ├── ic_play_arrow_black_36dp.png │ │ ├── ic_play_arrow_white_24dp.png │ │ ├── ic_skip_next_white_24dp.png │ │ └── ic_skip_previous_white_24dp.png │ │ ├── drawable-nodpi │ │ ├── album_jazz_blues.jpg │ │ └── album_youtube_audio_library_rock_2.jpg │ │ ├── drawable-xhdpi │ │ ├── ic_equalizer1_white_36dp.png │ │ ├── ic_equalizer2_white_36dp.png │ │ ├── ic_equalizer3_white_36dp.png │ │ ├── ic_launcher.png │ │ ├── ic_notification.png │ │ ├── ic_pause_black_36dp.png │ │ ├── ic_pause_white_24dp.png │ │ ├── ic_play_arrow_black_36dp.png │ │ ├── ic_play_arrow_white_24dp.png │ │ ├── ic_skip_next_white_24dp.png │ │ └── ic_skip_previous_white_24dp.png │ │ ├── drawable-xxhdpi │ │ ├── ic_equalizer1_white_36dp.png │ │ ├── ic_equalizer2_white_36dp.png │ │ ├── ic_equalizer3_white_36dp.png │ │ ├── ic_launcher.png │ │ ├── ic_notification.png │ │ ├── ic_pause_black_36dp.png │ │ ├── ic_pause_white_24dp.png │ │ ├── ic_play_arrow_black_36dp.png │ │ ├── ic_play_arrow_white_24dp.png │ │ ├── ic_skip_next_white_24dp.png │ │ └── ic_skip_previous_white_24dp.png │ │ ├── drawable-xxxhdpi │ │ ├── ic_equalizer1_white_36dp.png │ │ ├── ic_equalizer2_white_36dp.png │ │ ├── ic_equalizer3_white_36dp.png │ │ ├── ic_launcher.png │ │ ├── ic_notification.png │ │ ├── ic_pause_black_36dp.png │ │ ├── ic_pause_white_24dp.png │ │ ├── ic_play_arrow_black_36dp.png │ │ ├── ic_play_arrow_white_24dp.png │ │ ├── ic_skip_next_white_24dp.png │ │ └── ic_skip_previous_white_24dp.png │ │ ├── drawable │ │ └── ic_equalizer_white_36dp.xml │ │ ├── layout │ │ ├── activity_player.xml │ │ ├── include_toolbar.xml │ │ └── media_list_item.xml │ │ ├── raw │ │ ├── jazz_in_paris │ │ └── the_coldest_shoulder │ │ ├── values-h800dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ ├── strings_notifications.xml │ │ └── styles.xml └── settings.gradle └── final ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mobile ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── android │ │ └── musicplayercodelab │ │ ├── MediaItemViewHolder.java │ │ ├── MediaNotificationManager.java │ │ ├── MusicLibrary.java │ │ ├── MusicPlayerActivity.java │ │ ├── MusicService.java │ │ └── PlaybackManager.java │ └── res │ ├── drawable-hdpi │ ├── ic_equalizer1_white_36dp.png │ ├── ic_equalizer2_white_36dp.png │ ├── ic_equalizer3_white_36dp.png │ ├── ic_launcher.png │ ├── ic_notification.png │ ├── ic_pause_black_36dp.png │ ├── ic_pause_white_24dp.png │ ├── ic_play_arrow_black_36dp.png │ ├── ic_play_arrow_white_24dp.png │ ├── ic_skip_next_white_24dp.png │ └── ic_skip_previous_white_24dp.png │ ├── drawable-mdpi │ ├── ic_equalizer1_white_36dp.png │ ├── ic_equalizer2_white_36dp.png │ ├── ic_equalizer3_white_36dp.png │ ├── ic_launcher.png │ ├── ic_notification.png │ ├── ic_pause_black_36dp.png │ ├── ic_pause_white_24dp.png │ ├── ic_play_arrow_black_36dp.png │ ├── ic_play_arrow_white_24dp.png │ ├── ic_skip_next_white_24dp.png │ └── ic_skip_previous_white_24dp.png │ ├── drawable-nodpi │ ├── album_jazz_blues.jpg │ └── album_youtube_audio_library_rock_2.jpg │ ├── drawable-xhdpi │ ├── ic_equalizer1_white_36dp.png │ ├── ic_equalizer2_white_36dp.png │ ├── ic_equalizer3_white_36dp.png │ ├── ic_launcher.png │ ├── ic_notification.png │ ├── ic_pause_black_36dp.png │ ├── ic_pause_white_24dp.png │ ├── ic_play_arrow_black_36dp.png │ ├── ic_play_arrow_white_24dp.png │ ├── ic_skip_next_white_24dp.png │ └── ic_skip_previous_white_24dp.png │ ├── drawable-xxhdpi │ ├── ic_equalizer1_white_36dp.png │ ├── ic_equalizer2_white_36dp.png │ ├── ic_equalizer3_white_36dp.png │ ├── ic_launcher.png │ ├── ic_notification.png │ ├── ic_pause_black_36dp.png │ ├── ic_pause_white_24dp.png │ ├── ic_play_arrow_black_36dp.png │ ├── ic_play_arrow_white_24dp.png │ ├── ic_skip_next_white_24dp.png │ └── ic_skip_previous_white_24dp.png │ ├── drawable-xxxhdpi │ ├── ic_equalizer1_white_36dp.png │ ├── ic_equalizer2_white_36dp.png │ ├── ic_equalizer3_white_36dp.png │ ├── ic_launcher.png │ ├── ic_notification.png │ ├── ic_pause_black_36dp.png │ ├── ic_pause_white_24dp.png │ ├── ic_play_arrow_black_36dp.png │ ├── ic_play_arrow_white_24dp.png │ ├── ic_skip_next_white_24dp.png │ └── ic_skip_previous_white_24dp.png │ ├── drawable │ └── ic_equalizer_white_36dp.xml │ ├── layout │ ├── activity_player.xml │ ├── include_toolbar.xml │ └── media_list_item.xml │ ├── raw │ ├── jazz_in_paris │ └── the_coldest_shoulder │ ├── values-h800dp │ └── dimens.xml │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ ├── strings.xml │ ├── strings_notifications.xml │ └── styles.xml │ └── xml │ └── automotive_app_desc.xml └── settings.gradle /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | ### Before you contribute 9 | Before we can use your code, you must sign the 10 | [Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual) 11 | (CLA), which you can do online. The CLA is necessary mainly because you own the 12 | copyright to your changes, even after your contribution becomes part of our 13 | codebase, so we need your permission to use and distribute your code. We also 14 | need to be sure of various other things—for instance that you'll tell us if you 15 | know that your code infringes on other people's patents. You don't have to sign 16 | the CLA until after you've submitted your code for review and a member has 17 | approved it, but you must do it before we can put your code into our codebase. 18 | Before you start working on a larger contribution, you should get in touch with 19 | us first through the issue tracker with your idea so that we can help out and 20 | possibly guide you. Coordinating up front makes it much easier to avoid 21 | frustration later on. 22 | 23 | ### Code reviews 24 | All submissions, including submissions by project members, require review. We 25 | use Github pull requests for this purpose. 26 | 27 | ### The small print 28 | Contributions made by corporations are covered by a different agreement than 29 | the one above, the 30 | [Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Music Player Codelab 2 | 3 | This folder contains the source code for a Google I/O 2016 codelab. 4 | 5 | ### License 6 | 7 | ``` 8 | Copyright 2016 Google, Inc. 9 | 10 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 11 | license agreements. See the NOTICE file distributed with this work for 12 | additional information regarding copyright ownership. The ASF licenses this 13 | file to you under the Apache License, Version 2.0 (the "License"); you may not 14 | use this file except in compliance with the License. You may obtain a copy of 15 | the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 21 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 22 | License for the specific language governing permissions and limitations under 23 | the License. 24 | ``` 25 | -------------------------------------------------------------------------------- /base/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | .DS_Store 5 | /build 6 | *.iml 7 | -------------------------------------------------------------------------------- /base/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to 18 | // all sub-projects/modules. 19 | 20 | buildscript { 21 | repositories { 22 | jcenter() 23 | } 24 | dependencies { 25 | classpath 'com.android.tools.build:gradle:2.1.0' 26 | 27 | // NOTE: Do not place your application dependencies here; they belong 28 | // in the individual module build.gradle files 29 | } 30 | } 31 | 32 | allprojects { 33 | repositories { 34 | jcenter() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /base/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | # Project-wide Gradle settings. 17 | 18 | # IDE (e.g. Android Studio) users: 19 | # Gradle settings configured through the IDE *will override* 20 | # any settings specified in this file. 21 | 22 | # For more details on how to configure your build environment visit 23 | # http://www.gradle.org/docs/current/userguide/build_environment.html 24 | 25 | # Specifies the JVM arguments used for the daemon process. 26 | # The setting is particularly useful for tweaking memory settings. 27 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 28 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 29 | 30 | # When configured, Gradle will run in incubating parallel mode. 31 | # This option should only be used with decoupled projects. More details, visit 32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 33 | # org.gradle.parallel=true 34 | -------------------------------------------------------------------------------- /base/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /base/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 13 14:29:13 PDT 2016 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-2.10-all.zip 7 | -------------------------------------------------------------------------------- /base/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /base/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 | -------------------------------------------------------------------------------- /base/mobile/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /base/mobile/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | apply plugin: 'com.android.application' 17 | 18 | android { 19 | compileSdkVersion 23 20 | buildToolsVersion "23.0.3" 21 | 22 | defaultConfig { 23 | applicationId "com.example.android.musicplayercodelab" 24 | minSdkVersion 21 25 | targetSdkVersion 23 26 | versionCode 2 27 | versionName "1.1" 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_7 31 | targetCompatibility JavaVersion.VERSION_1_7 32 | } 33 | lintOptions { 34 | abortOnError true 35 | } 36 | } 37 | 38 | repositories { 39 | flatDir { 40 | dirs 'libs' 41 | } 42 | } 43 | 44 | dependencies { 45 | compile fileTree(dir: 'libs', include: ['*.jar']) 46 | compile 'com.android.support:support-v4:23.+' 47 | compile 'com.android.support:appcompat-v7:23.+' 48 | compile 'com.android.support:cardview-v7:23.+' 49 | } 50 | -------------------------------------------------------------------------------- /base/mobile/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /base/mobile/src/main/java/com/example/android/musicplayercodelab/MediaItemViewHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.app.Activity; 19 | import android.content.Context; 20 | import android.content.res.ColorStateList; 21 | import android.graphics.drawable.AnimationDrawable; 22 | import android.media.MediaDescription; 23 | import android.view.LayoutInflater; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | import android.widget.ImageView; 27 | import android.widget.TextView; 28 | 29 | class MediaItemViewHolder { 30 | 31 | static final int STATE_INVALID = -1; 32 | static final int STATE_NONE = 0; 33 | static final int STATE_PLAYABLE = 1; 34 | static final int STATE_PAUSED = 2; 35 | static final int STATE_PLAYING = 3; 36 | 37 | private static ColorStateList sColorStatePlaying; 38 | private static ColorStateList sColorStateNotPlaying; 39 | 40 | ImageView mImageView; 41 | TextView mTitleView; 42 | TextView mDescriptionView; 43 | 44 | static View setupView(Activity activity, View convertView, ViewGroup parent, 45 | MediaDescription description, int state) { 46 | 47 | if (sColorStateNotPlaying == null || sColorStatePlaying == null) { 48 | initializeColorStateLists(activity); 49 | } 50 | 51 | MediaItemViewHolder holder; 52 | 53 | Integer cachedState = STATE_INVALID; 54 | 55 | if (convertView == null) { 56 | convertView = LayoutInflater.from(activity) 57 | .inflate(R.layout.media_list_item, parent, false); 58 | holder = new MediaItemViewHolder(); 59 | holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); 60 | holder.mTitleView = (TextView) convertView.findViewById(R.id.title); 61 | holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); 62 | convertView.setTag(holder); 63 | } else { 64 | holder = (MediaItemViewHolder) convertView.getTag(); 65 | cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache); 66 | } 67 | 68 | holder.mTitleView.setText(description.getTitle()); 69 | holder.mDescriptionView.setText(description.getSubtitle()); 70 | 71 | // If the state of convertView is different, we need to adapt the view to the 72 | // new state. 73 | if (cachedState == null || cachedState != state) { 74 | switch (state) { 75 | case STATE_PLAYABLE: 76 | holder.mImageView.setImageDrawable( 77 | activity.getDrawable(R.drawable.ic_play_arrow_black_36dp)); 78 | holder.mImageView.setImageTintList(sColorStateNotPlaying); 79 | holder.mImageView.setVisibility(View.VISIBLE); 80 | break; 81 | case STATE_PLAYING: 82 | AnimationDrawable animation = (AnimationDrawable) 83 | activity.getDrawable(R.drawable.ic_equalizer_white_36dp); 84 | holder.mImageView.setImageDrawable(animation); 85 | holder.mImageView.setImageTintList(sColorStatePlaying); 86 | holder.mImageView.setVisibility(View.VISIBLE); 87 | animation.start(); 88 | break; 89 | case STATE_PAUSED: 90 | holder.mImageView.setImageDrawable( 91 | activity.getDrawable(R.drawable.ic_equalizer1_white_36dp)); 92 | holder.mImageView.setImageTintList(sColorStateNotPlaying); 93 | holder.mImageView.setVisibility(View.VISIBLE); 94 | break; 95 | default: 96 | holder.mImageView.setVisibility(View.GONE); 97 | } 98 | convertView.setTag(R.id.tag_mediaitem_state_cache, state); 99 | } 100 | 101 | return convertView; 102 | } 103 | 104 | static private void initializeColorStateLists(Context ctx) { 105 | sColorStateNotPlaying = ColorStateList.valueOf(ctx.getResources().getColor( 106 | R.color.media_item_icon_not_playing)); 107 | sColorStatePlaying = ColorStateList.valueOf(ctx.getResources().getColor( 108 | R.color.media_item_icon_playing)); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /base/mobile/src/main/java/com/example/android/musicplayercodelab/MusicLibrary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.musicplayercodelab; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.media.MediaMetadata; 23 | import android.media.browse.MediaBrowser; 24 | 25 | import java.util.ArrayList; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.TreeMap; 29 | 30 | class MusicLibrary { 31 | 32 | private static final TreeMap music = new TreeMap<>(); 33 | private static final HashMap albumRes = new HashMap<>(); 34 | private static final HashMap musicRes = new HashMap<>(); 35 | static { 36 | createMediaMetadata("Jazz_In_Paris", "Jazz in Paris", 37 | "Media Right Productions", "Jazz & Blues", "Jazz", 103, 38 | R.raw.jazz_in_paris, R.drawable.album_jazz_blues, "album_jazz_blues"); 39 | createMediaMetadata("The_Coldest_Shoulder", 40 | "The Coldest Shoulder", "The 126ers", "Youtube Audio Library Rock 2", "Rock", 160, 41 | R.raw.the_coldest_shoulder, R.drawable.album_youtube_audio_library_rock_2, 42 | "album_youtube_audio_library_rock_2"); 43 | } 44 | 45 | public static String getRoot() { 46 | return ""; 47 | } 48 | 49 | public static String getSongUri(String mediaId) { 50 | return "android.resource://" + BuildConfig.APPLICATION_ID + "/" + getMusicRes(mediaId); 51 | } 52 | 53 | private static String getAlbumArtUri(String albumArtResName) { 54 | return "android.resource://" + BuildConfig.APPLICATION_ID + "/drawable/" + albumArtResName; 55 | } 56 | 57 | private static int getMusicRes(String mediaId) { 58 | return musicRes.containsKey(mediaId) ? musicRes.get(mediaId) : 0; 59 | } 60 | 61 | private static int getAlbumRes(String mediaId) { 62 | return albumRes.containsKey(mediaId) ? albumRes.get(mediaId) : 0; 63 | } 64 | 65 | public static Bitmap getAlbumBitmap(Context ctx, String mediaId) { 66 | return BitmapFactory.decodeResource(ctx.getResources(), MusicLibrary.getAlbumRes(mediaId)); 67 | } 68 | 69 | public static List getMediaItems() { 70 | List result = new ArrayList<>(); 71 | for (MediaMetadata metadata: music.values()) { 72 | result.add(new MediaBrowser.MediaItem(metadata.getDescription(), 73 | MediaBrowser.MediaItem.FLAG_PLAYABLE)); 74 | } 75 | return result; 76 | } 77 | 78 | public static String getPreviousSong(String currentMediaId) { 79 | String prevMediaId = music.lowerKey(currentMediaId); 80 | if (prevMediaId == null) { 81 | prevMediaId = music.firstKey(); 82 | } 83 | return prevMediaId; 84 | } 85 | 86 | public static String getNextSong(String currentMediaId) { 87 | String nextMediaId = music.higherKey(currentMediaId); 88 | if (nextMediaId == null) { 89 | nextMediaId = music.firstKey(); 90 | } 91 | return nextMediaId; 92 | } 93 | 94 | public static MediaMetadata getMetadata(Context ctx, String mediaId) { 95 | MediaMetadata metadataWithoutBitmap = music.get(mediaId); 96 | Bitmap albumArt = getAlbumBitmap(ctx, mediaId); 97 | 98 | // Since MediaMetadata is immutable, we need to create a copy to set the album art 99 | // We don't set it initially on all items so that they don't take unnecessary memory 100 | MediaMetadata.Builder builder = new MediaMetadata.Builder(); 101 | for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID, 102 | MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST, 103 | MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) { 104 | builder.putString(key, metadataWithoutBitmap.getString(key)); 105 | } 106 | builder.putLong(MediaMetadata.METADATA_KEY_DURATION, 107 | metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION)); 108 | builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt); 109 | return builder.build(); 110 | } 111 | 112 | private static void createMediaMetadata(String mediaId, String title, String artist, 113 | String album, String genre, long duration, int musicResId, int albumArtResId, 114 | String albumArtResName) { 115 | music.put(mediaId, 116 | new MediaMetadata.Builder() 117 | .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, mediaId) 118 | .putString(MediaMetadata.METADATA_KEY_ALBUM, album) 119 | .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) 120 | .putLong(MediaMetadata.METADATA_KEY_DURATION, duration * 1000) 121 | .putString(MediaMetadata.METADATA_KEY_GENRE, genre) 122 | .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, getAlbumArtUri(albumArtResName)) 123 | .putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, getAlbumArtUri(albumArtResName)) 124 | .putString(MediaMetadata.METADATA_KEY_TITLE, title) 125 | .build()); 126 | albumRes.put(mediaId, albumArtResId); 127 | musicRes.put(mediaId, musicResId); 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /base/mobile/src/main/java/com/example/android/musicplayercodelab/MusicPlayerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.app.Activity; 19 | import android.media.MediaMetadata; 20 | import android.media.browse.MediaBrowser; 21 | import android.media.session.PlaybackState; 22 | import android.os.Bundle; 23 | import android.support.v7.app.AppCompatActivity; 24 | import android.support.v7.widget.Toolbar; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.widget.AdapterView; 28 | import android.widget.ArrayAdapter; 29 | import android.widget.ImageButton; 30 | import android.widget.ImageView; 31 | import android.widget.ListView; 32 | import android.widget.TextView; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | /** 38 | * An Activity to browse and play media. 39 | */ 40 | public class MusicPlayerActivity extends AppCompatActivity { 41 | 42 | private BrowseAdapter mBrowserAdapter; 43 | private ImageButton mPlayPause; 44 | private TextView mTitle; 45 | private TextView mSubtitle; 46 | private ImageView mAlbumArt; 47 | private ViewGroup mPlaybackControls; 48 | 49 | private MediaMetadata mCurrentMetadata; 50 | private PlaybackState mCurrentState; 51 | 52 | // ------------ CHANGE 1 - REMOVE FOLLOWING LINE FOR PLAYBACK ON A SERVICE 53 | private PlaybackManager mPlaybackManager; 54 | 55 | /* ------------ CHANGE 1 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 56 | private MediaBrowser mMediaBrowser; 57 | 58 | private final MediaBrowser.ConnectionCallback mConnectionCallback = 59 | new MediaBrowser.ConnectionCallback() { 60 | @Override 61 | public void onConnected() { 62 | mMediaBrowser.subscribe(mMediaBrowser.getRoot(), mSubscriptionCallback); 63 | MediaController mediaController = new MediaController( 64 | MusicPlayerActivity.this, mMediaBrowser.getSessionToken()); 65 | updatePlaybackState(mediaController.getPlaybackState()); 66 | updateMetadata(mediaController.getMetadata()); 67 | mediaController.registerCallback(mMediaControllerCallback); 68 | setMediaController(mediaController); 69 | } 70 | }; 71 | 72 | // Receive callbacks from the MediaController. Here we update our state such as which queue 73 | // is being shown, the current title and description and the PlaybackState. 74 | private final MediaController.Callback mMediaControllerCallback = new MediaController.Callback() { 75 | @Override 76 | public void onMetadataChanged(MediaMetadata metadata) { 77 | updateMetadata(metadata); 78 | mBrowserAdapter.notifyDataSetChanged(); 79 | } 80 | 81 | @Override 82 | public void onPlaybackStateChanged(PlaybackState state) { 83 | updatePlaybackState(state); 84 | mBrowserAdapter.notifyDataSetChanged(); 85 | } 86 | 87 | @Override 88 | public void onSessionDestroyed() { 89 | updatePlaybackState(null); 90 | mBrowserAdapter.notifyDataSetChanged(); 91 | } 92 | }; 93 | 94 | private final MediaBrowser.SubscriptionCallback mSubscriptionCallback = 95 | new MediaBrowser.SubscriptionCallback() { 96 | @Override 97 | public void onChildrenLoaded(String parentId, List children) { 98 | onMediaLoaded(children); 99 | } 100 | }; 101 | // ------------ CHANGE 1 - END OF PLAYBACK ON A SERVICE SNIPPET */ 102 | 103 | private void onMediaLoaded(List media) { 104 | mBrowserAdapter.clear(); 105 | mBrowserAdapter.addAll(media); 106 | mBrowserAdapter.notifyDataSetChanged(); 107 | } 108 | 109 | private void onMediaItemSelected(MediaBrowser.MediaItem item) { 110 | if (item.isPlayable()) { 111 | // ------------ CHANGE 2 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE 112 | MediaMetadata metadata = MusicLibrary.getMetadata(this, item.getMediaId()); 113 | mPlaybackManager.play(metadata); 114 | updateMetadata(metadata); 115 | 116 | /* ------------ CHANGE 2 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 117 | getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null); 118 | // ------------ CHANGE 2 - END OF PLAYBACK ON A SERVICE SNIPPET */ 119 | } 120 | } 121 | 122 | 123 | @Override 124 | public void onCreate(Bundle savedInstanceState) { 125 | super.onCreate(savedInstanceState); 126 | setContentView(R.layout.activity_player); 127 | setTitle(getString(R.string.app_name)); 128 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); 129 | 130 | 131 | mBrowserAdapter = new BrowseAdapter(this); 132 | 133 | ListView listView = (ListView) findViewById(R.id.list_view); 134 | listView.setAdapter(mBrowserAdapter); 135 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 136 | @Override 137 | public void onItemClick(AdapterView parent, View view, int position, long id) { 138 | MediaBrowser.MediaItem item = mBrowserAdapter.getItem(position); 139 | onMediaItemSelected(item); 140 | } 141 | }); 142 | 143 | // Playback controls configuration: 144 | mPlaybackControls = (ViewGroup) findViewById(R.id.playback_controls); 145 | mPlayPause = (ImageButton) findViewById(R.id.play_pause); 146 | mPlayPause.setEnabled(true); 147 | mPlayPause.setOnClickListener(mPlaybackButtonListener); 148 | 149 | mTitle = (TextView) findViewById(R.id.title); 150 | mSubtitle = (TextView) findViewById(R.id.artist); 151 | mAlbumArt = (ImageView) findViewById(R.id.album_art); 152 | } 153 | 154 | 155 | @Override 156 | public void onStart() { 157 | super.onStart(); 158 | 159 | // ------------ CHANGE 3 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE 160 | mPlaybackManager = new PlaybackManager(this, new PlaybackManager.Callback() { 161 | @Override 162 | public void onPlaybackStatusChanged(PlaybackState state) { 163 | mBrowserAdapter.notifyDataSetChanged(); 164 | updatePlaybackState(state); 165 | } 166 | }); 167 | onMediaLoaded(MusicLibrary.getMediaItems()); 168 | 169 | /* ------------ CHANGE 3 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 170 | mMediaBrowser = new MediaBrowser(this, 171 | new ComponentName(this, MusicService.class), mConnectionCallback, null); 172 | mMediaBrowser.connect(); 173 | // ------------ CHANGE 3 - END OF PLAYBACK ON A SERVICE SNIPPET */ 174 | } 175 | 176 | @Override 177 | public void onStop() { 178 | super.onStop(); 179 | // ------------ CHANGE 4 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE 180 | mPlaybackManager.stop(); 181 | 182 | /* ------------ CHANGE 4 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 183 | if (getMediaController() != null) { 184 | getMediaController().unregisterCallback(mMediaControllerCallback); 185 | } 186 | if (mMediaBrowser != null && mMediaBrowser.isConnected()) { 187 | mMediaBrowser.unsubscribe(mCurrentMetadata.getDescription().getMediaId()); 188 | } 189 | // ------------ CHANGE 4 - END OF PLAYBACK ON A SERVICE SNIPPET */ 190 | } 191 | 192 | private void updatePlaybackState(PlaybackState state) { 193 | mCurrentState = state; 194 | if (state == null || state.getState() == PlaybackState.STATE_PAUSED || 195 | state.getState() == PlaybackState.STATE_STOPPED) { 196 | mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_play_arrow_black_36dp)); 197 | } else { 198 | mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_pause_black_36dp)); 199 | } 200 | mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE); 201 | } 202 | 203 | private void updateMetadata(MediaMetadata metadata) { 204 | mCurrentMetadata = metadata; 205 | mTitle.setText(metadata == null ? "" : metadata.getDescription().getTitle()); 206 | mSubtitle.setText(metadata == null ? "" : metadata.getDescription().getSubtitle()); 207 | mAlbumArt.setImageBitmap(metadata == null ? null : MusicLibrary.getAlbumBitmap(this, 208 | metadata.getDescription().getMediaId())); 209 | mBrowserAdapter.notifyDataSetChanged(); 210 | } 211 | 212 | // An adapter for showing the list of browsed MediaItem's 213 | private class BrowseAdapter extends ArrayAdapter { 214 | 215 | public BrowseAdapter(Activity context) { 216 | super(context, R.layout.media_list_item, new ArrayList()); 217 | } 218 | 219 | @Override 220 | public View getView(int position, View convertView, ViewGroup parent) { 221 | MediaBrowser.MediaItem item = getItem(position); 222 | int itemState = MediaItemViewHolder.STATE_NONE; 223 | if (item.isPlayable()) { 224 | String itemMediaId = item.getDescription().getMediaId(); 225 | int playbackState = PlaybackState.STATE_NONE; 226 | if (mCurrentState != null) { 227 | playbackState = mCurrentState.getState(); 228 | } 229 | if (mCurrentMetadata != null && 230 | itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) { 231 | if (playbackState == PlaybackState.STATE_PLAYING || 232 | playbackState == PlaybackState.STATE_BUFFERING) { 233 | itemState = MediaItemViewHolder.STATE_PLAYING; 234 | } else if (playbackState != PlaybackState.STATE_ERROR) { 235 | itemState = MediaItemViewHolder.STATE_PAUSED; 236 | } 237 | } 238 | } 239 | return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent, 240 | item.getDescription(), itemState); 241 | } 242 | } 243 | 244 | private final View.OnClickListener mPlaybackButtonListener = new View.OnClickListener() { 245 | @Override 246 | public void onClick(View v) { 247 | final int state = mCurrentState == null ? 248 | PlaybackState.STATE_NONE : mCurrentState.getState(); 249 | if (state == PlaybackState.STATE_PAUSED || 250 | state == PlaybackState.STATE_STOPPED || 251 | state == PlaybackState.STATE_NONE) { 252 | 253 | if (mCurrentMetadata == null) { 254 | mCurrentMetadata = MusicLibrary.getMetadata(MusicPlayerActivity.this, 255 | MusicLibrary.getMediaItems().get(0).getMediaId()); 256 | updateMetadata(mCurrentMetadata); 257 | } 258 | // ------------ CHANGE 5 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE 259 | mPlaybackManager.play(mCurrentMetadata); 260 | 261 | /* ------------ CHANGE 5 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 262 | getMediaController().getTransportControls().playFromMediaId( 263 | mCurrentMetadata.getDescription().getMediaId(), null); 264 | // ------------ CHANGE 5 - END OF PLAYBACK ON A SERVICE SNIPPET */ 265 | 266 | } else { 267 | // ------------ CHANGE 6 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE 268 | mPlaybackManager.pause(); 269 | 270 | /* ------------ CHANGE 6 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE 271 | getMediaController().getTransportControls().pause(); 272 | // ------------ CHANGE 6 - END OF PLAYBACK ON A SERVICE SNIPPET */ 273 | } 274 | } 275 | }; 276 | 277 | } 278 | -------------------------------------------------------------------------------- /base/mobile/src/main/java/com/example/android/musicplayercodelab/PlaybackManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.content.Context; 19 | import android.media.AudioManager; 20 | import android.media.MediaMetadata; 21 | import android.media.MediaPlayer; 22 | import android.media.session.PlaybackState; 23 | import android.net.Uri; 24 | import android.os.PowerManager; 25 | import android.os.SystemClock; 26 | 27 | import java.io.IOException; 28 | 29 | import static android.media.MediaPlayer.OnCompletionListener; 30 | 31 | /** 32 | * Handles media playback using a {@link MediaPlayer}. 33 | */ 34 | class PlaybackManager implements AudioManager.OnAudioFocusChangeListener, 35 | MediaPlayer.OnCompletionListener { 36 | 37 | private final Context mContext; 38 | private int mState; 39 | private boolean mPlayOnFocusGain; 40 | private volatile MediaMetadata mCurrentMedia; 41 | 42 | private MediaPlayer mMediaPlayer; 43 | 44 | private final Callback mCallback; 45 | private final AudioManager mAudioManager; 46 | 47 | public PlaybackManager(Context context, Callback callback) { 48 | this.mContext = context; 49 | this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 50 | this.mCallback = callback; 51 | } 52 | 53 | public boolean isPlaying() { 54 | return mPlayOnFocusGain || (mMediaPlayer != null && mMediaPlayer.isPlaying()); 55 | } 56 | 57 | public MediaMetadata getCurrentMedia() { 58 | return mCurrentMedia; 59 | } 60 | 61 | public String getCurrentMediaId() { 62 | return mCurrentMedia == null ? null : mCurrentMedia.getDescription().getMediaId(); 63 | } 64 | 65 | public int getCurrentStreamPosition() { 66 | return mMediaPlayer != null ? mMediaPlayer.getCurrentPosition() : 0; 67 | } 68 | 69 | public void play(MediaMetadata metadata) { 70 | String mediaId = metadata.getDescription().getMediaId(); 71 | boolean mediaChanged = (mCurrentMedia == null || !getCurrentMediaId().equals(mediaId)); 72 | 73 | if (mMediaPlayer == null) { 74 | mMediaPlayer = new MediaPlayer(); 75 | mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 76 | mMediaPlayer.setWakeMode(mContext.getApplicationContext(), 77 | PowerManager.PARTIAL_WAKE_LOCK); 78 | mMediaPlayer.setOnCompletionListener(this); 79 | } else { 80 | if (mediaChanged) { 81 | mMediaPlayer.reset(); 82 | } 83 | } 84 | 85 | if (mediaChanged) { 86 | mCurrentMedia = metadata; 87 | try { 88 | mMediaPlayer.setDataSource(mContext.getApplicationContext(), 89 | Uri.parse(MusicLibrary.getSongUri(mediaId))); 90 | mMediaPlayer.prepare(); 91 | } catch (IOException e) { 92 | throw new RuntimeException(e); 93 | } 94 | } 95 | 96 | if (tryToGetAudioFocus()) { 97 | mPlayOnFocusGain = false; 98 | mMediaPlayer.start(); 99 | mState = PlaybackState.STATE_PLAYING; 100 | updatePlaybackState(); 101 | } else { 102 | mPlayOnFocusGain = true; 103 | } 104 | } 105 | 106 | public void pause() { 107 | if (isPlaying()) { 108 | mMediaPlayer.pause(); 109 | mAudioManager.abandonAudioFocus(this); 110 | } 111 | mState = PlaybackState.STATE_PAUSED; 112 | updatePlaybackState(); 113 | } 114 | 115 | public void stop() { 116 | mState = PlaybackState.STATE_STOPPED; 117 | updatePlaybackState(); 118 | // Give up Audio focus 119 | mAudioManager.abandonAudioFocus(this); 120 | // Relax all resources 121 | releaseMediaPlayer(); 122 | } 123 | 124 | /** 125 | * Try to get the system audio focus. 126 | */ 127 | private boolean tryToGetAudioFocus() { 128 | int result = mAudioManager.requestAudioFocus( 129 | this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); 130 | return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED; 131 | } 132 | 133 | /** 134 | * Called by AudioManager on audio focus changes. 135 | * Implementation of {@link AudioManager.OnAudioFocusChangeListener} 136 | */ 137 | @Override 138 | public void onAudioFocusChange(int focusChange) { 139 | boolean gotFullFocus = false; 140 | boolean canDuck = false; 141 | if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { 142 | gotFullFocus = true; 143 | 144 | } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS || 145 | focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || 146 | focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { 147 | // We have lost focus. If we can duck (low playback volume), we can keep playing. 148 | // Otherwise, we need to pause the playback. 149 | canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK; 150 | } 151 | 152 | if (gotFullFocus || canDuck) { 153 | if (mMediaPlayer != null) { 154 | if (mPlayOnFocusGain) { 155 | mPlayOnFocusGain = false; 156 | mMediaPlayer.start(); 157 | mState = PlaybackState.STATE_PLAYING; 158 | updatePlaybackState(); 159 | } 160 | float volume = canDuck ? 0.2f : 1.0f; 161 | mMediaPlayer.setVolume(volume, volume); 162 | } 163 | } else if (mState == PlaybackState.STATE_PLAYING) { 164 | mMediaPlayer.pause(); 165 | mState = PlaybackState.STATE_PAUSED; 166 | updatePlaybackState(); 167 | } 168 | } 169 | 170 | /** 171 | * Called when media player is done playing current song. 172 | * 173 | * @see OnCompletionListener 174 | */ 175 | @Override 176 | public void onCompletion(MediaPlayer player) { 177 | stop(); 178 | } 179 | 180 | /** 181 | * Releases resources used by the service for playback. 182 | */ 183 | private void releaseMediaPlayer() { 184 | if (mMediaPlayer != null) { 185 | mMediaPlayer.reset(); 186 | mMediaPlayer.release(); 187 | mMediaPlayer = null; 188 | } 189 | } 190 | 191 | private long getAvailableActions() { 192 | long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | 193 | PlaybackState.ACTION_PLAY_FROM_SEARCH | 194 | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS; 195 | if (isPlaying()) { 196 | actions |= PlaybackState.ACTION_PAUSE; 197 | } 198 | return actions; 199 | } 200 | 201 | private void updatePlaybackState() { 202 | if (mCallback == null) { 203 | return; 204 | } 205 | PlaybackState.Builder stateBuilder = new PlaybackState.Builder() 206 | .setActions(getAvailableActions()); 207 | 208 | stateBuilder.setState(mState, getCurrentStreamPosition(), 1.0f, SystemClock.elapsedRealtime()); 209 | mCallback.onPlaybackStatusChanged(stateBuilder.build()); 210 | } 211 | 212 | public interface Callback { 213 | void onPlaybackStatusChanged(PlaybackState state); 214 | } 215 | 216 | } 217 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_notification.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-hdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-hdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_notification.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-mdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-mdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-nodpi/album_jazz_blues.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-nodpi/album_jazz_blues.jpg -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-nodpi/album_youtube_audio_library_rock_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-nodpi/album_youtube_audio_library_rock_2.jpg -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_notification.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_notification.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_notification.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable-xxxhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/drawable-xxxhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /base/mobile/src/main/res/drawable/ic_equalizer_white_36dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/layout/activity_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 26 | 27 | 29 | 30 | 37 | 38 | 44 | 45 | 49 | 57 | 66 | 75 | 83 | 84 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/layout/include_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 27 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/layout/media_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 32 | 33 | 40 | 41 | 49 | 50 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/raw/jazz_in_paris: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/raw/jazz_in_paris -------------------------------------------------------------------------------- /base/mobile/src/main/res/raw/the_coldest_shoulder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/base/mobile/src/main/res/raw/the_coldest_shoulder -------------------------------------------------------------------------------- /base/mobile/src/main/res/values-h800dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 96dp 20 | 21 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | #00B8D4 19 | #ffff5722 20 | @color/bt_accent 21 | #ccc 22 | 23 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 8dp 20 | 64dp 21 | 8dp 22 | 23 | 24 | 72dp 25 | 12dp 26 | 60dp 27 | 28 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | Music Player Codelab 20 | Play item 21 | play or pause 22 | Song currently playing 23 | Artist of currently playing song 24 | Extra info for currently playing song 25 | 26 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/strings_notifications.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | Pause 19 | Play 20 | Previous 21 | Next 22 | 23 | -------------------------------------------------------------------------------- /base/mobile/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /base/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':mobile' 2 | -------------------------------------------------------------------------------- /final/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | .DS_Store 5 | /build 6 | *.iml 7 | -------------------------------------------------------------------------------- /final/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to 18 | // all sub-projects/modules. 19 | 20 | buildscript { 21 | repositories { 22 | jcenter() 23 | } 24 | dependencies { 25 | classpath 'com.android.tools.build:gradle:2.1.0' 26 | 27 | // NOTE: Do not place your application dependencies here; they belong 28 | // in the individual module build.gradle files 29 | } 30 | } 31 | 32 | allprojects { 33 | repositories { 34 | jcenter() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /final/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | # Project-wide Gradle settings. 17 | 18 | # IDE (e.g. Android Studio) users: 19 | # Gradle settings configured through the IDE *will override* 20 | # any settings specified in this file. 21 | 22 | # For more details on how to configure your build environment visit 23 | # http://www.gradle.org/docs/current/userguide/build_environment.html 24 | 25 | # Specifies the JVM arguments used for the daemon process. 26 | # The setting is particularly useful for tweaking memory settings. 27 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 28 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 29 | 30 | # When configured, Gradle will run in incubating parallel mode. 31 | # This option should only be used with decoupled projects. More details, visit 32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 33 | # org.gradle.parallel=true 34 | -------------------------------------------------------------------------------- /final/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /final/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 13 14:33:23 PDT 2016 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-2.10-all.zip 7 | -------------------------------------------------------------------------------- /final/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /final/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 | -------------------------------------------------------------------------------- /final/mobile/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /final/mobile/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | apply plugin: 'com.android.application' 17 | 18 | android { 19 | compileSdkVersion 23 20 | buildToolsVersion "23.0.3" 21 | 22 | defaultConfig { 23 | applicationId "com.example.android.musicplayercodelab" 24 | minSdkVersion 21 25 | targetSdkVersion 23 26 | versionCode 2 27 | versionName "1.1" 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_7 31 | targetCompatibility JavaVersion.VERSION_1_7 32 | } 33 | lintOptions { 34 | abortOnError true 35 | } 36 | } 37 | 38 | repositories { 39 | flatDir { 40 | dirs 'libs' 41 | } 42 | } 43 | 44 | dependencies { 45 | compile fileTree(dir: 'libs', include: ['*.jar']) 46 | compile 'com.android.support:support-v4:23.+' 47 | compile 'com.android.support:appcompat-v7:23.+' 48 | compile 'com.android.support:cardview-v7:23.+' 49 | } 50 | -------------------------------------------------------------------------------- /final/mobile/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | 23 | 28 | 29 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/MediaItemViewHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.app.Activity; 19 | import android.content.Context; 20 | import android.content.res.ColorStateList; 21 | import android.graphics.drawable.AnimationDrawable; 22 | import android.media.MediaDescription; 23 | import android.view.LayoutInflater; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | import android.widget.ImageView; 27 | import android.widget.TextView; 28 | 29 | class MediaItemViewHolder { 30 | 31 | static final int STATE_INVALID = -1; 32 | static final int STATE_NONE = 0; 33 | static final int STATE_PLAYABLE = 1; 34 | static final int STATE_PAUSED = 2; 35 | static final int STATE_PLAYING = 3; 36 | 37 | private static ColorStateList sColorStatePlaying; 38 | private static ColorStateList sColorStateNotPlaying; 39 | 40 | ImageView mImageView; 41 | TextView mTitleView; 42 | TextView mDescriptionView; 43 | 44 | static View setupView(Activity activity, View convertView, ViewGroup parent, 45 | MediaDescription description, int state) { 46 | 47 | if (sColorStateNotPlaying == null || sColorStatePlaying == null) { 48 | initializeColorStateLists(activity); 49 | } 50 | 51 | MediaItemViewHolder holder; 52 | 53 | Integer cachedState = STATE_INVALID; 54 | 55 | if (convertView == null) { 56 | convertView = LayoutInflater.from(activity) 57 | .inflate(R.layout.media_list_item, parent, false); 58 | holder = new MediaItemViewHolder(); 59 | holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); 60 | holder.mTitleView = (TextView) convertView.findViewById(R.id.title); 61 | holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); 62 | convertView.setTag(holder); 63 | } else { 64 | holder = (MediaItemViewHolder) convertView.getTag(); 65 | cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache); 66 | } 67 | 68 | holder.mTitleView.setText(description.getTitle()); 69 | holder.mDescriptionView.setText(description.getSubtitle()); 70 | 71 | // If the state of convertView is different, we need to adapt the view to the 72 | // new state. 73 | if (cachedState == null || cachedState != state) { 74 | switch (state) { 75 | case STATE_PLAYABLE: 76 | holder.mImageView.setImageDrawable( 77 | activity.getDrawable(R.drawable.ic_play_arrow_black_36dp)); 78 | holder.mImageView.setImageTintList(sColorStateNotPlaying); 79 | holder.mImageView.setVisibility(View.VISIBLE); 80 | break; 81 | case STATE_PLAYING: 82 | AnimationDrawable animation = (AnimationDrawable) 83 | activity.getDrawable(R.drawable.ic_equalizer_white_36dp); 84 | holder.mImageView.setImageDrawable(animation); 85 | holder.mImageView.setImageTintList(sColorStatePlaying); 86 | holder.mImageView.setVisibility(View.VISIBLE); 87 | animation.start(); 88 | break; 89 | case STATE_PAUSED: 90 | holder.mImageView.setImageDrawable( 91 | activity.getDrawable(R.drawable.ic_equalizer1_white_36dp)); 92 | holder.mImageView.setImageTintList(sColorStateNotPlaying); 93 | holder.mImageView.setVisibility(View.VISIBLE); 94 | break; 95 | default: 96 | holder.mImageView.setVisibility(View.GONE); 97 | } 98 | convertView.setTag(R.id.tag_mediaitem_state_cache, state); 99 | } 100 | 101 | return convertView; 102 | } 103 | 104 | static private void initializeColorStateLists(Context ctx) { 105 | sColorStateNotPlaying = ColorStateList.valueOf(ctx.getResources().getColor( 106 | R.color.media_item_icon_not_playing)); 107 | sColorStatePlaying = ColorStateList.valueOf(ctx.getResources().getColor( 108 | R.color.media_item_icon_playing)); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/MediaNotificationManager.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.android.musicplayercodelab; 16 | 17 | import android.app.Notification; 18 | import android.app.NotificationManager; 19 | import android.app.PendingIntent; 20 | import android.content.BroadcastReceiver; 21 | import android.content.Context; 22 | import android.content.Intent; 23 | import android.content.IntentFilter; 24 | import android.media.MediaDescription; 25 | import android.media.MediaMetadata; 26 | import android.media.session.MediaSession; 27 | import android.media.session.PlaybackState; 28 | 29 | /** 30 | * Keeps track of a notification and updates it automatically for a given 31 | * MediaSession. This is required so that the music service 32 | * don't get killed during playback. 33 | */ 34 | public class MediaNotificationManager extends BroadcastReceiver { 35 | private static final int NOTIFICATION_ID = 412; 36 | private static final int REQUEST_CODE = 100; 37 | 38 | private static final String ACTION_PAUSE = "com.example.android.musicplayercodelab.pause"; 39 | private static final String ACTION_PLAY = "com.example.android.musicplayercodelab.play"; 40 | private static final String ACTION_NEXT = "com.example.android.musicplayercodelab.next"; 41 | private static final String ACTION_PREV = "com.example.android.musicplayercodelab.prev"; 42 | 43 | private final MusicService mService; 44 | 45 | private final NotificationManager mNotificationManager; 46 | 47 | private final Notification.Action mPlayAction; 48 | private final Notification.Action mPauseAction; 49 | private final Notification.Action mNextAction; 50 | private final Notification.Action mPrevAction; 51 | 52 | private boolean mStarted; 53 | 54 | public MediaNotificationManager(MusicService service) { 55 | mService = service; 56 | 57 | String pkg = mService.getPackageName(); 58 | PendingIntent playIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, 59 | new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); 60 | PendingIntent pauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, 61 | new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); 62 | PendingIntent nextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, 63 | new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); 64 | PendingIntent prevIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, 65 | new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); 66 | 67 | mPlayAction = new Notification.Action(R.drawable.ic_play_arrow_white_24dp, 68 | mService.getString(R.string.label_play), playIntent); 69 | mPauseAction = new Notification.Action(R.drawable.ic_pause_white_24dp, 70 | mService.getString(R.string.label_pause), pauseIntent); 71 | mNextAction = new Notification.Action(R.drawable.ic_skip_next_white_24dp, 72 | mService.getString(R.string.label_next), nextIntent); 73 | mPrevAction = new Notification.Action(R.drawable.ic_skip_previous_white_24dp, 74 | mService.getString(R.string.label_previous), prevIntent); 75 | 76 | IntentFilter filter = new IntentFilter(); 77 | filter.addAction(ACTION_NEXT); 78 | filter.addAction(ACTION_PAUSE); 79 | filter.addAction(ACTION_PLAY); 80 | filter.addAction(ACTION_PREV); 81 | 82 | mService.registerReceiver(this, filter); 83 | 84 | 85 | mNotificationManager = (NotificationManager) mService 86 | .getSystemService(Context.NOTIFICATION_SERVICE); 87 | 88 | // Cancel all notifications to handle the case where the Service was killed and 89 | // restarted by the system. 90 | mNotificationManager.cancelAll(); 91 | } 92 | 93 | @Override 94 | public void onReceive(Context context, Intent intent) { 95 | final String action = intent.getAction(); 96 | switch (action) { 97 | case ACTION_PAUSE: 98 | mService.mCallback.onPause(); 99 | break; 100 | case ACTION_PLAY: 101 | mService.mCallback.onPlay(); 102 | break; 103 | case ACTION_NEXT: 104 | mService.mCallback.onSkipToNext(); 105 | break; 106 | case ACTION_PREV: 107 | mService.mCallback.onSkipToPrevious(); 108 | break; 109 | } 110 | } 111 | 112 | public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) { 113 | if (state == null || state.getState() == PlaybackState.STATE_STOPPED || 114 | state.getState() == PlaybackState.STATE_NONE) { 115 | mService.stopForeground(true); 116 | try { 117 | mService.unregisterReceiver(this); 118 | } catch (IllegalArgumentException ex) { 119 | // ignore receiver not registered 120 | } 121 | mService.stopSelf(); 122 | return; 123 | } 124 | if (metadata == null) { 125 | return; 126 | } 127 | boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING; 128 | Notification.Builder notificationBuilder = new Notification.Builder(mService); 129 | MediaDescription description = metadata.getDescription(); 130 | 131 | notificationBuilder 132 | .setStyle(new Notification.MediaStyle() 133 | .setMediaSession(token) 134 | .setShowActionsInCompactView(0, 1, 2)) 135 | .setColor(mService.getApplication().getResources().getColor(R.color.notification_bg)) 136 | .setSmallIcon(R.drawable.ic_notification) 137 | .setVisibility(Notification.VISIBILITY_PUBLIC) 138 | .setContentIntent(createContentIntent()) 139 | .setContentTitle(description.getTitle()) 140 | .setContentText(description.getSubtitle()) 141 | .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId())) 142 | .setOngoing(isPlaying) 143 | .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0) 144 | .setShowWhen(isPlaying) 145 | .setUsesChronometer(isPlaying); 146 | 147 | // If skip to next action is enabled 148 | if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { 149 | notificationBuilder.addAction(mPrevAction); 150 | } 151 | 152 | notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction); 153 | 154 | // If skip to prev action is enabled 155 | if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { 156 | notificationBuilder.addAction(mNextAction); 157 | } 158 | 159 | Notification notification = notificationBuilder.build(); 160 | 161 | if (isPlaying && !mStarted) { 162 | mService.startService(new Intent(mService.getApplicationContext(), MusicService.class)); 163 | mService.startForeground(NOTIFICATION_ID, notification); 164 | mStarted = true; 165 | } else { 166 | if (!isPlaying) { 167 | mService.stopForeground(false); 168 | mStarted = false; 169 | } 170 | mNotificationManager.notify(NOTIFICATION_ID, notification); 171 | } 172 | } 173 | 174 | private PendingIntent createContentIntent() { 175 | Intent openUI = new Intent(mService, MusicPlayerActivity.class); 176 | openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 177 | return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, 178 | PendingIntent.FLAG_CANCEL_CURRENT); 179 | } 180 | 181 | } -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/MusicLibrary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.musicplayercodelab; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.media.MediaMetadata; 23 | import android.media.browse.MediaBrowser; 24 | 25 | import java.util.ArrayList; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.TreeMap; 29 | 30 | class MusicLibrary { 31 | 32 | private static final TreeMap music = new TreeMap<>(); 33 | private static final HashMap albumRes = new HashMap<>(); 34 | private static final HashMap musicRes = new HashMap<>(); 35 | static { 36 | createMediaMetadata("Jazz_In_Paris", "Jazz in Paris", 37 | "Media Right Productions", "Jazz & Blues", "Jazz", 103, 38 | R.raw.jazz_in_paris, R.drawable.album_jazz_blues, "album_jazz_blues"); 39 | createMediaMetadata("The_Coldest_Shoulder", 40 | "The Coldest Shoulder", "The 126ers", "Youtube Audio Library Rock 2", "Rock", 160, 41 | R.raw.the_coldest_shoulder, R.drawable.album_youtube_audio_library_rock_2, 42 | "album_youtube_audio_library_rock_2"); 43 | } 44 | 45 | public static String getRoot() { 46 | return ""; 47 | } 48 | 49 | public static String getSongUri(String mediaId) { 50 | return "android.resource://" + BuildConfig.APPLICATION_ID + "/" + getMusicRes(mediaId); 51 | } 52 | 53 | private static String getAlbumArtUri(String albumArtResName) { 54 | return "android.resource://" + BuildConfig.APPLICATION_ID + "/drawable/" + albumArtResName; 55 | } 56 | 57 | private static int getMusicRes(String mediaId) { 58 | return musicRes.containsKey(mediaId) ? musicRes.get(mediaId) : 0; 59 | } 60 | 61 | private static int getAlbumRes(String mediaId) { 62 | return albumRes.containsKey(mediaId) ? albumRes.get(mediaId) : 0; 63 | } 64 | 65 | public static Bitmap getAlbumBitmap(Context ctx, String mediaId) { 66 | return BitmapFactory.decodeResource(ctx.getResources(), MusicLibrary.getAlbumRes(mediaId)); 67 | } 68 | 69 | public static List getMediaItems() { 70 | List result = new ArrayList<>(); 71 | for (MediaMetadata metadata: music.values()) { 72 | result.add(new MediaBrowser.MediaItem(metadata.getDescription(), 73 | MediaBrowser.MediaItem.FLAG_PLAYABLE)); 74 | } 75 | return result; 76 | } 77 | 78 | public static String getPreviousSong(String currentMediaId) { 79 | String prevMediaId = music.lowerKey(currentMediaId); 80 | if (prevMediaId == null) { 81 | prevMediaId = music.firstKey(); 82 | } 83 | return prevMediaId; 84 | } 85 | 86 | public static String getNextSong(String currentMediaId) { 87 | String nextMediaId = music.higherKey(currentMediaId); 88 | if (nextMediaId == null) { 89 | nextMediaId = music.firstKey(); 90 | } 91 | return nextMediaId; 92 | } 93 | 94 | public static MediaMetadata getMetadata(Context ctx, String mediaId) { 95 | MediaMetadata metadataWithoutBitmap = music.get(mediaId); 96 | Bitmap albumArt = getAlbumBitmap(ctx, mediaId); 97 | 98 | // Since MediaMetadata is immutable, we need to create a copy to set the album art 99 | // We don't set it initially on all items so that they don't take unnecessary memory 100 | MediaMetadata.Builder builder = new MediaMetadata.Builder(); 101 | for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID, 102 | MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST, 103 | MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) { 104 | builder.putString(key, metadataWithoutBitmap.getString(key)); 105 | } 106 | builder.putLong(MediaMetadata.METADATA_KEY_DURATION, 107 | metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION)); 108 | builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt); 109 | return builder.build(); 110 | } 111 | 112 | private static void createMediaMetadata(String mediaId, String title, String artist, 113 | String album, String genre, long duration, int musicResId, int albumArtResId, 114 | String albumArtResName) { 115 | music.put(mediaId, 116 | new MediaMetadata.Builder() 117 | .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, mediaId) 118 | .putString(MediaMetadata.METADATA_KEY_ALBUM, album) 119 | .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) 120 | .putLong(MediaMetadata.METADATA_KEY_DURATION, duration * 1000) 121 | .putString(MediaMetadata.METADATA_KEY_GENRE, genre) 122 | .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, getAlbumArtUri(albumArtResName)) 123 | .putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, getAlbumArtUri(albumArtResName)) 124 | .putString(MediaMetadata.METADATA_KEY_TITLE, title) 125 | .build()); 126 | albumRes.put(mediaId, albumArtResId); 127 | musicRes.put(mediaId, musicResId); 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/MusicPlayerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.app.Activity; 19 | import android.content.ComponentName; 20 | import android.media.MediaMetadata; 21 | import android.media.browse.MediaBrowser; 22 | import android.media.session.MediaController; 23 | import android.media.session.PlaybackState; 24 | import android.os.Bundle; 25 | import android.support.v7.app.AppCompatActivity; 26 | import android.support.v7.widget.Toolbar; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.widget.AdapterView; 30 | import android.widget.ArrayAdapter; 31 | import android.widget.ImageButton; 32 | import android.widget.ImageView; 33 | import android.widget.ListView; 34 | import android.widget.TextView; 35 | 36 | import java.util.ArrayList; 37 | import java.util.List; 38 | 39 | /** 40 | * An Activity to browse and play media. 41 | */ 42 | public class MusicPlayerActivity extends AppCompatActivity { 43 | 44 | private BrowseAdapter mBrowserAdapter; 45 | private ImageButton mPlayPause; 46 | private TextView mTitle; 47 | private TextView mSubtitle; 48 | private ImageView mAlbumArt; 49 | private ViewGroup mPlaybackControls; 50 | 51 | private MediaMetadata mCurrentMetadata; 52 | private PlaybackState mCurrentState; 53 | 54 | private MediaBrowser mMediaBrowser; 55 | 56 | private final MediaBrowser.ConnectionCallback mConnectionCallback = 57 | new MediaBrowser.ConnectionCallback() { 58 | @Override 59 | public void onConnected() { 60 | mMediaBrowser.subscribe(mMediaBrowser.getRoot(), mSubscriptionCallback); 61 | MediaController mediaController = new MediaController( 62 | MusicPlayerActivity.this, mMediaBrowser.getSessionToken()); 63 | updatePlaybackState(mediaController.getPlaybackState()); 64 | updateMetadata(mediaController.getMetadata()); 65 | mediaController.registerCallback(mMediaControllerCallback); 66 | setMediaController(mediaController); 67 | } 68 | }; 69 | 70 | // Receive callbacks from the MediaController. Here we update our state such as which queue 71 | // is being shown, the current title and description and the PlaybackState. 72 | private final MediaController.Callback mMediaControllerCallback = new MediaController.Callback() { 73 | @Override 74 | public void onMetadataChanged(MediaMetadata metadata) { 75 | updateMetadata(metadata); 76 | mBrowserAdapter.notifyDataSetChanged(); 77 | } 78 | 79 | @Override 80 | public void onPlaybackStateChanged(PlaybackState state) { 81 | updatePlaybackState(state); 82 | mBrowserAdapter.notifyDataSetChanged(); 83 | } 84 | 85 | @Override 86 | public void onSessionDestroyed() { 87 | updatePlaybackState(null); 88 | mBrowserAdapter.notifyDataSetChanged(); 89 | } 90 | }; 91 | 92 | private final MediaBrowser.SubscriptionCallback mSubscriptionCallback = 93 | new MediaBrowser.SubscriptionCallback() { 94 | @Override 95 | public void onChildrenLoaded(String parentId, List children) { 96 | onMediaLoaded(children); 97 | } 98 | }; 99 | 100 | private void onMediaLoaded(List media) { 101 | mBrowserAdapter.clear(); 102 | mBrowserAdapter.addAll(media); 103 | mBrowserAdapter.notifyDataSetChanged(); 104 | } 105 | 106 | private void onMediaItemSelected(MediaBrowser.MediaItem item) { 107 | if (item.isPlayable()) { 108 | getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null); 109 | } 110 | } 111 | 112 | 113 | @Override 114 | public void onCreate(Bundle savedInstanceState) { 115 | super.onCreate(savedInstanceState); 116 | setContentView(R.layout.activity_player); 117 | setTitle(getString(R.string.app_name)); 118 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); 119 | 120 | 121 | mBrowserAdapter = new BrowseAdapter(this); 122 | 123 | ListView listView = (ListView) findViewById(R.id.list_view); 124 | listView.setAdapter(mBrowserAdapter); 125 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 126 | @Override 127 | public void onItemClick(AdapterView parent, View view, int position, long id) { 128 | MediaBrowser.MediaItem item = mBrowserAdapter.getItem(position); 129 | onMediaItemSelected(item); 130 | } 131 | }); 132 | 133 | // Playback controls configuration: 134 | mPlaybackControls = (ViewGroup) findViewById(R.id.playback_controls); 135 | mPlayPause = (ImageButton) findViewById(R.id.play_pause); 136 | mPlayPause.setEnabled(true); 137 | mPlayPause.setOnClickListener(mPlaybackButtonListener); 138 | 139 | mTitle = (TextView) findViewById(R.id.title); 140 | mSubtitle = (TextView) findViewById(R.id.artist); 141 | mAlbumArt = (ImageView) findViewById(R.id.album_art); 142 | } 143 | 144 | 145 | @Override 146 | public void onStart() { 147 | super.onStart(); 148 | 149 | mMediaBrowser = new MediaBrowser(this, 150 | new ComponentName(this, MusicService.class), mConnectionCallback, null); 151 | mMediaBrowser.connect(); 152 | } 153 | 154 | @Override 155 | public void onStop() { 156 | super.onStop(); 157 | if (getMediaController() != null) { 158 | getMediaController().unregisterCallback(mMediaControllerCallback); 159 | } 160 | if (mMediaBrowser != null && mMediaBrowser.isConnected()) { 161 | mMediaBrowser.unsubscribe(mCurrentMetadata.getDescription().getMediaId()); 162 | } 163 | } 164 | 165 | private void updatePlaybackState(PlaybackState state) { 166 | mCurrentState = state; 167 | if (state == null || state.getState() == PlaybackState.STATE_PAUSED || 168 | state.getState() == PlaybackState.STATE_STOPPED) { 169 | mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_play_arrow_black_36dp)); 170 | } else { 171 | mPlayPause.setImageDrawable(getDrawable(R.drawable.ic_pause_black_36dp)); 172 | } 173 | mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE); 174 | } 175 | 176 | private void updateMetadata(MediaMetadata metadata) { 177 | mCurrentMetadata = metadata; 178 | mTitle.setText(metadata == null ? "" : metadata.getDescription().getTitle()); 179 | mSubtitle.setText(metadata == null ? "" : metadata.getDescription().getSubtitle()); 180 | mAlbumArt.setImageBitmap(metadata == null ? null : MusicLibrary.getAlbumBitmap(this, 181 | metadata.getDescription().getMediaId())); 182 | mBrowserAdapter.notifyDataSetChanged(); 183 | } 184 | 185 | // An adapter for showing the list of browsed MediaItem's 186 | private class BrowseAdapter extends ArrayAdapter { 187 | 188 | public BrowseAdapter(Activity context) { 189 | super(context, R.layout.media_list_item, new ArrayList()); 190 | } 191 | 192 | @Override 193 | public View getView(int position, View convertView, ViewGroup parent) { 194 | MediaBrowser.MediaItem item = getItem(position); 195 | int itemState = MediaItemViewHolder.STATE_NONE; 196 | if (item.isPlayable()) { 197 | String itemMediaId = item.getDescription().getMediaId(); 198 | int playbackState = PlaybackState.STATE_NONE; 199 | if (mCurrentState != null) { 200 | playbackState = mCurrentState.getState(); 201 | } 202 | if (mCurrentMetadata != null && 203 | itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) { 204 | if (playbackState == PlaybackState.STATE_PLAYING || 205 | playbackState == PlaybackState.STATE_BUFFERING) { 206 | itemState = MediaItemViewHolder.STATE_PLAYING; 207 | } else if (playbackState != PlaybackState.STATE_ERROR) { 208 | itemState = MediaItemViewHolder.STATE_PAUSED; 209 | } 210 | } 211 | } 212 | return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent, 213 | item.getDescription(), itemState); 214 | } 215 | } 216 | 217 | private final View.OnClickListener mPlaybackButtonListener = new View.OnClickListener() { 218 | @Override 219 | public void onClick(View v) { 220 | final int state = mCurrentState == null ? 221 | PlaybackState.STATE_NONE : mCurrentState.getState(); 222 | if (state == PlaybackState.STATE_PAUSED || 223 | state == PlaybackState.STATE_STOPPED || 224 | state == PlaybackState.STATE_NONE) { 225 | 226 | if (mCurrentMetadata == null) { 227 | mCurrentMetadata = MusicLibrary.getMetadata(MusicPlayerActivity.this, 228 | MusicLibrary.getMediaItems().get(0).getMediaId()); 229 | updateMetadata(mCurrentMetadata); 230 | } 231 | getMediaController().getTransportControls().playFromMediaId( 232 | mCurrentMetadata.getDescription().getMediaId(), null); 233 | 234 | } else { 235 | getMediaController().getTransportControls().pause(); 236 | } 237 | } 238 | }; 239 | } 240 | -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/MusicService.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.android.musicplayercodelab; 16 | 17 | import android.media.MediaMetadata; 18 | import android.media.browse.MediaBrowser.MediaItem; 19 | import android.media.session.MediaSession; 20 | import android.media.session.PlaybackState; 21 | import android.os.Bundle; 22 | import android.service.media.MediaBrowserService; 23 | 24 | import java.util.List; 25 | 26 | public class MusicService extends MediaBrowserService { 27 | 28 | private MediaSession mSession; 29 | private PlaybackManager mPlayback; 30 | 31 | final MediaSession.Callback mCallback = new MediaSession.Callback() { 32 | @Override 33 | public void onPlayFromMediaId(String mediaId, Bundle extras) { 34 | mSession.setActive(true); 35 | MediaMetadata metadata = MusicLibrary.getMetadata(MusicService.this, mediaId); 36 | mSession.setMetadata(metadata); 37 | mPlayback.play(metadata); 38 | } 39 | 40 | @Override 41 | public void onPlay() { 42 | if (mPlayback.getCurrentMediaId() != null) { 43 | onPlayFromMediaId(mPlayback.getCurrentMediaId(), null); 44 | } 45 | } 46 | 47 | @Override 48 | public void onPause() { 49 | mPlayback.pause(); 50 | } 51 | 52 | @Override 53 | public void onStop() { 54 | stopSelf(); 55 | } 56 | 57 | @Override 58 | public void onSkipToNext() { 59 | onPlayFromMediaId(MusicLibrary.getNextSong(mPlayback.getCurrentMediaId()), null); 60 | } 61 | 62 | @Override 63 | public void onSkipToPrevious() { 64 | onPlayFromMediaId(MusicLibrary.getPreviousSong(mPlayback.getCurrentMediaId()), null); 65 | } 66 | }; 67 | 68 | @Override 69 | public void onCreate() { 70 | super.onCreate(); 71 | 72 | // Start a new MediaSession 73 | mSession = new MediaSession(this, "MusicService"); 74 | mSession.setCallback(mCallback); 75 | mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | 76 | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); 77 | setSessionToken(mSession.getSessionToken()); 78 | 79 | final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this); 80 | 81 | mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() { 82 | @Override 83 | public void onPlaybackStatusChanged(PlaybackState state) { 84 | mSession.setPlaybackState(state); 85 | mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken()); 86 | } 87 | }); 88 | } 89 | 90 | @Override 91 | public void onDestroy() { 92 | mPlayback.stop(); 93 | mSession.release(); 94 | } 95 | 96 | @Override 97 | public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) { 98 | return new BrowserRoot(MusicLibrary.getRoot(), null); 99 | } 100 | 101 | @Override 102 | public void onLoadChildren(final String parentMediaId, final Result> result) { 103 | result.sendResult(MusicLibrary.getMediaItems()); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /final/mobile/src/main/java/com/example/android/musicplayercodelab/PlaybackManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.example.android.musicplayercodelab; 17 | 18 | import android.content.Context; 19 | import android.media.AudioManager; 20 | import android.media.MediaMetadata; 21 | import android.media.MediaPlayer; 22 | import android.media.session.PlaybackState; 23 | import android.net.Uri; 24 | import android.os.PowerManager; 25 | import android.os.SystemClock; 26 | 27 | import java.io.IOException; 28 | 29 | import static android.media.MediaPlayer.OnCompletionListener; 30 | 31 | /** 32 | * Handles media playback using a {@link MediaPlayer}. 33 | */ 34 | class PlaybackManager implements AudioManager.OnAudioFocusChangeListener, 35 | MediaPlayer.OnCompletionListener { 36 | 37 | private final Context mContext; 38 | private int mState; 39 | private boolean mPlayOnFocusGain; 40 | private volatile MediaMetadata mCurrentMedia; 41 | 42 | private MediaPlayer mMediaPlayer; 43 | 44 | private final Callback mCallback; 45 | private final AudioManager mAudioManager; 46 | 47 | public PlaybackManager(Context context, Callback callback) { 48 | this.mContext = context; 49 | this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 50 | this.mCallback = callback; 51 | } 52 | 53 | public boolean isPlaying() { 54 | return mPlayOnFocusGain || (mMediaPlayer != null && mMediaPlayer.isPlaying()); 55 | } 56 | 57 | public MediaMetadata getCurrentMedia() { 58 | return mCurrentMedia; 59 | } 60 | 61 | public String getCurrentMediaId() { 62 | return mCurrentMedia == null ? null : mCurrentMedia.getDescription().getMediaId(); 63 | } 64 | 65 | public int getCurrentStreamPosition() { 66 | return mMediaPlayer != null ? mMediaPlayer.getCurrentPosition() : 0; 67 | } 68 | 69 | public void play(MediaMetadata metadata) { 70 | String mediaId = metadata.getDescription().getMediaId(); 71 | boolean mediaChanged = (mCurrentMedia == null || !getCurrentMediaId().equals(mediaId)); 72 | 73 | if (mMediaPlayer == null) { 74 | mMediaPlayer = new MediaPlayer(); 75 | mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 76 | mMediaPlayer.setWakeMode(mContext.getApplicationContext(), 77 | PowerManager.PARTIAL_WAKE_LOCK); 78 | mMediaPlayer.setOnCompletionListener(this); 79 | } else { 80 | if (mediaChanged) { 81 | mMediaPlayer.reset(); 82 | } 83 | } 84 | 85 | if (mediaChanged) { 86 | mCurrentMedia = metadata; 87 | try { 88 | mMediaPlayer.setDataSource(mContext.getApplicationContext(), 89 | Uri.parse(MusicLibrary.getSongUri(mediaId))); 90 | mMediaPlayer.prepare(); 91 | } catch (IOException e) { 92 | throw new RuntimeException(e); 93 | } 94 | } 95 | 96 | if (tryToGetAudioFocus()) { 97 | mPlayOnFocusGain = false; 98 | mMediaPlayer.start(); 99 | mState = PlaybackState.STATE_PLAYING; 100 | updatePlaybackState(); 101 | } else { 102 | mPlayOnFocusGain = true; 103 | } 104 | } 105 | 106 | public void pause() { 107 | if (isPlaying()) { 108 | mMediaPlayer.pause(); 109 | mAudioManager.abandonAudioFocus(this); 110 | } 111 | mState = PlaybackState.STATE_PAUSED; 112 | updatePlaybackState(); 113 | } 114 | 115 | public void stop() { 116 | mState = PlaybackState.STATE_STOPPED; 117 | updatePlaybackState(); 118 | // Give up Audio focus 119 | mAudioManager.abandonAudioFocus(this); 120 | // Relax all resources 121 | releaseMediaPlayer(); 122 | } 123 | 124 | /** 125 | * Try to get the system audio focus. 126 | */ 127 | private boolean tryToGetAudioFocus() { 128 | int result = mAudioManager.requestAudioFocus( 129 | this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); 130 | return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED; 131 | } 132 | 133 | /** 134 | * Called by AudioManager on audio focus changes. 135 | * Implementation of {@link AudioManager.OnAudioFocusChangeListener} 136 | */ 137 | @Override 138 | public void onAudioFocusChange(int focusChange) { 139 | boolean gotFullFocus = false; 140 | boolean canDuck = false; 141 | if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { 142 | gotFullFocus = true; 143 | 144 | } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS || 145 | focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || 146 | focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { 147 | // We have lost focus. If we can duck (low playback volume), we can keep playing. 148 | // Otherwise, we need to pause the playback. 149 | canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK; 150 | } 151 | 152 | if (gotFullFocus || canDuck) { 153 | if (mMediaPlayer != null) { 154 | if (mPlayOnFocusGain) { 155 | mPlayOnFocusGain = false; 156 | mMediaPlayer.start(); 157 | mState = PlaybackState.STATE_PLAYING; 158 | updatePlaybackState(); 159 | } 160 | float volume = canDuck ? 0.2f : 1.0f; 161 | mMediaPlayer.setVolume(volume, volume); 162 | } 163 | } else if (mState == PlaybackState.STATE_PLAYING) { 164 | mMediaPlayer.pause(); 165 | mState = PlaybackState.STATE_PAUSED; 166 | updatePlaybackState(); 167 | } 168 | } 169 | 170 | /** 171 | * Called when media player is done playing current song. 172 | * 173 | * @see OnCompletionListener 174 | */ 175 | @Override 176 | public void onCompletion(MediaPlayer player) { 177 | stop(); 178 | } 179 | 180 | /** 181 | * Releases resources used by the service for playback. 182 | */ 183 | private void releaseMediaPlayer() { 184 | if (mMediaPlayer != null) { 185 | mMediaPlayer.reset(); 186 | mMediaPlayer.release(); 187 | mMediaPlayer = null; 188 | } 189 | } 190 | 191 | private long getAvailableActions() { 192 | long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | 193 | PlaybackState.ACTION_PLAY_FROM_SEARCH | 194 | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS; 195 | if (isPlaying()) { 196 | actions |= PlaybackState.ACTION_PAUSE; 197 | } 198 | return actions; 199 | } 200 | 201 | private void updatePlaybackState() { 202 | if (mCallback == null) { 203 | return; 204 | } 205 | PlaybackState.Builder stateBuilder = new PlaybackState.Builder() 206 | .setActions(getAvailableActions()); 207 | 208 | stateBuilder.setState(mState, getCurrentStreamPosition(), 1.0f, SystemClock.elapsedRealtime()); 209 | mCallback.onPlaybackStatusChanged(stateBuilder.build()); 210 | } 211 | 212 | public interface Callback { 213 | void onPlaybackStatusChanged(PlaybackState state); 214 | } 215 | 216 | } 217 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_notification.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-hdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-hdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_notification.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-mdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-mdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-nodpi/album_jazz_blues.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-nodpi/album_jazz_blues.jpg -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-nodpi/album_youtube_audio_library_rock_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-nodpi/album_youtube_audio_library_rock_2.jpg -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_notification.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_notification.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer1_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer1_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer2_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer2_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer3_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_equalizer3_white_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_notification.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_pause_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_pause_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_black_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_black_36dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_skip_next_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_skip_next_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable-xxxhdpi/ic_skip_previous_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/drawable-xxxhdpi/ic_skip_previous_white_24dp.png -------------------------------------------------------------------------------- /final/mobile/src/main/res/drawable/ic_equalizer_white_36dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/layout/activity_player.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 26 | 27 | 29 | 30 | 37 | 38 | 44 | 45 | 49 | 57 | 66 | 75 | 83 | 84 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/layout/include_toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 27 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/layout/media_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 32 | 33 | 40 | 41 | 49 | 50 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/raw/jazz_in_paris: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/raw/jazz_in_paris -------------------------------------------------------------------------------- /final/mobile/src/main/res/raw/the_coldest_shoulder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlecodelabs/android-music-player/bad0bbbdd7cd2c9d7197c40cbcb5d1733604298c/final/mobile/src/main/res/raw/the_coldest_shoulder -------------------------------------------------------------------------------- /final/mobile/src/main/res/values-h800dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 96dp 20 | 21 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | #00B8D4 19 | #ffff5722 20 | @color/bt_accent 21 | #ccc 22 | 23 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 8dp 20 | 64dp 21 | 8dp 22 | 23 | 24 | 72dp 25 | 12dp 26 | 60dp 27 | 28 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | Music Player Codelab 20 | Play item 21 | play or pause 22 | Song currently playing 23 | Artist of currently playing song 24 | Extra info for currently playing song 25 | 26 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/strings_notifications.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | Pause 19 | Play 20 | Previous 21 | Next 22 | 23 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /final/mobile/src/main/res/xml/automotive_app_desc.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /final/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':mobile' 2 | --------------------------------------------------------------------------------