This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
gradlew
143 lines (125 loc) · 5.17 KB
/
gradlew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2013 Google Inc. All rights reserved.
*
* 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.android.grafika;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.util.Log;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
import java.io.File;
import java.io.IOException;
/**
* Play a movie from a file on disk. Output goes to a TextureView.
* <p>
* Currently video-only.
* <p>
* Contrast with PlayMovieSurfaceActivity, which uses a SurfaceView. Much of the code is
* the same, but here we can handle the aspect ratio adjustment with a simple matrix,
* rather than a custom layout.
* <p>
* TODO: investigate crash when screen is rotated while movie is playing (need
* to have onPause() wait for playback to stop)
*/
public class PlayMovieActivity extends Activity implements OnItemSelectedListener,
TextureView.SurfaceTextureListener, MoviePlayer.PlayerFeedback {
private static final String TAG = MainActivity.TAG;
private TextureView mTextureView;
private String[] mMovieFiles;
private int mSelectedMovie;
private boolean mShowStopLabel;
private MoviePlayer.PlayTask mPlayTask;
private boolean mSurfaceTextureReady = false;
private final Object mStopper = new Object(); // used to signal stop
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_movie);
mTextureView = (TextureView) findViewById(R.id.movie_texture_view);
mTextureView.setSurfaceTextureListener(this);
// Populate file-selection spinner.
Spinner spinner = (Spinner) findViewById(R.id.playMovieFile_spinner);
// Need to create one of these fancy ArrayAdapter thingies, and specify the generic layout
// for the widget itself.
mMovieFiles = MiscUtils.getFiles(getFilesDir(), "*.mp4");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, mMovieFiles);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner.
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
updateControls();
}
@Override
protected void onResume() {
Log.d(TAG, "PlayMovieActivity onResume");
super.onResume();
}
@Override
protected void onPause() {
Log.d(TAG, "PlayMovieActivity onPause");
super.onPause();
// We're not keeping track of the state in static fields, so we need to shut the
// playback down. Ideally we'd preserve the state so that the player would continue
// after a device rotation.
//
// We want to be sure that the player won't continue to send frames after we pause,
// because we're tearing the view down. So we wait for it to stop here.
if (mPlayTask != null) {
stopPlayback();
mPlayTask.waitForStop();
}
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture st, int width, int height) {
// There's a short delay between the start of the activity and the initialization
// of the SurfaceTexture that backs the TextureView. We don't want to try to
// send a video stream to the TextureView before it has initialized, so we disable
// the "play" button until this callback fires.
Log.d(TAG, "SurfaceTexture ready (" + width + "x" + height + ")");
mSurfaceTextureReady = true;
updateControls();
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture st, int width, int height) {
// ignore
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture st) {
mSurfaceTextureReady = false;
// assume activity is pausing, so don't need to update controls
return true; // caller should release ST
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// ignore
}
/*
* Called when the movie Spinner gets touched.
*/
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Spinner spinner = (Spinner) parent;
mSelectedMovie = spinner.getSelectedItemPosition();
Log.d(TAG, "onItemSelected: " + mSelectedMo