1a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim/*
2a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Copyright (C) 2015 The Android Open Source Project
3a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
4a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Licensed under the Apache License, Version 2.0 (the "License");
5a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * you may not use this file except in compliance with the License.
6a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * You may obtain a copy of the License at
7a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
8a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *      http://www.apache.org/licenses/LICENSE-2.0
9a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
10a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Unless required by applicable law or agreed to in writing, software
11a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * distributed under the License is distributed on an "AS IS" BASIS,
12a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * See the License for the specific language governing permissions and
14a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * limitations under the License.
15a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim */
16a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
17a907614755847b2630561a1e5949b2b416600d97Sungsoo Limpackage com.example.android.supportv4.media;
18a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
19a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.os.Bundle;
207a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Choimport android.support.v4.app.FragmentActivity;
21a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.support.v4.media.MediaBrowserCompat;
22a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.support.v4.media.session.MediaControllerCompat;
23a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
247a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Choimport com.example.android.supportv4.R;
257a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Cho
26a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim/**
27a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Main activity for the music player.
28a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim */
297a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Chopublic class MediaBrowserSupport extends FragmentActivity
307a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Cho        implements BrowseFragment.FragmentDataHelper {
31a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
32a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    @Override
33a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public void onCreate(Bundle savedInstanceState) {
34a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        super.onCreate(savedInstanceState);
35a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        setContentView(R.layout.activity_player);
36a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        if (savedInstanceState == null) {
377a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Cho            getSupportFragmentManager().beginTransaction()
38a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .add(R.id.container, BrowseFragment.newInstance(null))
39a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .commit();
40a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        }
41a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
42a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
43a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    @Override
44a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public void onMediaItemSelected(MediaBrowserCompat.MediaItem item) {
45a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        if (item.isPlayable()) {
465e796344324f2214162daa2072b36960d5346a3aJaewan Kim            MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
475e796344324f2214162daa2072b36960d5346a3aJaewan Kim            if (mediaController != null) {
485e796344324f2214162daa2072b36960d5346a3aJaewan Kim                mediaController.getTransportControls().playFromMediaId(item.getMediaId(), null);
495e796344324f2214162daa2072b36960d5346a3aJaewan Kim                QueueFragment queueFragment = QueueFragment.newInstance();
505e796344324f2214162daa2072b36960d5346a3aJaewan Kim                getSupportFragmentManager().beginTransaction()
515e796344324f2214162daa2072b36960d5346a3aJaewan Kim                        .replace(R.id.container, queueFragment)
525e796344324f2214162daa2072b36960d5346a3aJaewan Kim                        .addToBackStack(null)
535e796344324f2214162daa2072b36960d5346a3aJaewan Kim                        .commit();
545e796344324f2214162daa2072b36960d5346a3aJaewan Kim            }
55a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        } else if (item.isBrowsable()) {
567a37b5e2010dd1e9a8775fc217b0e7043ed06417Donghyun Cho            getSupportFragmentManager().beginTransaction()
57a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .replace(R.id.container, BrowseFragment.newInstance(item.getMediaId()))
58a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .addToBackStack(null)
59a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .commit();
60a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        }
61a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
62a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
63a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public void setMediaController(MediaControllerCompat mediaController) {
645e796344324f2214162daa2072b36960d5346a3aJaewan Kim        MediaControllerCompat.setMediaController(this, mediaController);
65a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
66a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim}
67