/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.supportv4.media;

import android.view.KeyEvent;
import com.example.android.supportv4.R;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

import android.support.v4.media.TransportController;

public class TransportControllerActivity extends Activity {

    /**
     * TODO: Set the path variable to a streaming video URL or a local media
     * file path.
     */
    private VideoView mVideoView;
    private TransportController mTransportController;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.videoview);

        // Find the video player in our UI.
        mVideoView = (VideoView) findViewById(R.id.surface_view);

        // Create transport controller to control video; use the standard
        // control callbacks that knows how to talk to a MediaPlayerControl.
        mTransportController = new TransportController(this,
                new TransportController.PlayerControlCallbacks(mVideoView));

        // We're just playing a built-in demo video.
        mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +
                "/" + R.raw.videoviewdemo));
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (super.dispatchKeyEvent(event)) {
            return true;
        }

        // If the UI didn't handle the key, give the transport controller
        // a crack at it.
        return mTransportController.dispatchKeyEvent(event);
    }
}

@@ -1198,16 +1198,1036 @@
 oller;%0A%0A
+    /**%0A     * Handle media buttons to start/stop video playback.  Real implementations%0A     * will probably handle more buttons, like skip and fast-forward.%0A     */%0A    public class PlayerControlCallbacks extends TransportController.Callbacks %7B%0A        public boolean onMediaButtonDown(int keyCode, KeyEvent event) %7B%0A            switch (keyCode) %7B%0A                case TransportController.KEYCODE_MEDIA_PLAY:%0A                    mVideoView.start();%0A                    return true;%0A                case TransportController.KEYCODE_MEDIA_PAUSE:%0A                case KeyEvent.KEYCODE_MEDIA_STOP:%0A                    mVideoView.pause();%0A                    return true;%0A                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:%0A                case KeyEvent.KEYCODE_HEADSETHOOK:%0A                    if (mVideoView.isPlaying()) %7B%0A                        mVideoView.pause();%0A                    %7D else %7B%0A                        mVideoView.start();%0A                    %7D%0A            %7D%0A            return true;%0A        %7D%0A    %7D%0A%0A
     @Ove
@@ -2224,32 +2224,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -2677,49 +2677,13 @@
 his,
-%0A                new TransportController.
+ new 
 Play
@@ -2701,26 +2701,16 @@
 llbacks(
-mVideoView
 ));%0A%0A   

Move media key handling to here.