use of android.widget.MediaController in project Tusky by tuskyapp.
the class ViewVideoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_video);
final ProgressBar progressBar = findViewById(R.id.video_progress);
VideoView videoView = findViewById(R.id.video_player);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setTitle(null);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowHomeEnabled(true);
}
String url = getIntent().getStringExtra("url");
videoView.setVideoPath(url);
MediaController controller = new MediaController(this);
controller.setMediaPlayer(videoView);
videoView.setMediaController(controller);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressBar.setVisibility(View.GONE);
mp.setLooping(true);
hideToolbarAfterDelay();
}
});
videoView.start();
videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
handler.removeCallbacksAndMessages(null);
toolbar.animate().cancel();
toolbar.setAlpha(1);
toolbar.setVisibility(View.VISIBLE);
hideToolbarAfterDelay();
}
return false;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.BLACK);
}
}
use of android.widget.MediaController in project wcs-android-sdk-samples by flashphoner.
the class StreamRecordingActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stream_recording);
/**
* Initialization of the API.
*/
Flashphoner.init(this);
mWcsUrlView = (EditText) findViewById(R.id.wcs_url);
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
mWcsUrlView.setText(sharedPref.getString("wcs_url", getString(R.string.wcs_url)));
mStatusView = (TextView) findViewById(R.id.status);
mStartButton = (Button) findViewById(R.id.connect_button);
/**
* Connection to server will be established and stream will be published when Record button is clicked.
*/
mStartButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mStartButton.getTag() == null || Integer.valueOf(R.string.action_start).equals(mStartButton.getTag())) {
String url;
final String streamName;
try {
uri = new URI(mWcsUrlView.getText().toString());
url = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort();
streamName = uri.getPath().replaceAll("/", "");
} catch (URISyntaxException e) {
mStatusView.setText("Wrong uri");
return;
}
/**
* The options for connection session are set.
* WCS server URL is passed when SessionOptions object is created.
* SurfaceViewRenderer to be used to display video from the camera is set with method SessionOptions.setLocalRenderer().
*/
SessionOptions sessionOptions = new SessionOptions(url);
sessionOptions.setLocalRenderer(localRender);
/**
* Session for connection to WCS server is created with method createSession().
*/
session = Flashphoner.createSession(sessionOptions);
/**
* Callback functions for session status events are added to make appropriate changes in controls of the interface and publish stream when connection is established.
*/
session.on(new SessionEvent() {
@Override
public void onAppData(Data data) {
}
@Override
public void onConnected(final Connection connection) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mStartButton.setText(R.string.action_stop);
mStartButton.setTag(R.string.action_stop);
mStartButton.setEnabled(true);
mStatusView.setText(connection.getStatus());
/**
* The options for the stream to publish are set.
* The stream name is passed when StreamOptions object is created.
* To enable stream recording, option 'record' is set to 'true' with method StreamOptions.setRecord().
*/
StreamOptions streamOptions = new StreamOptions(streamName);
streamOptions.setRecord(true);
/**
* Stream is created with method Session.createStream().
*/
publishStream = session.createStream(streamOptions);
/**
* Callback function for stream status change is added to display the status.
*/
publishStream.on(new StreamStatusEvent() {
@Override
public void onStreamStatus(final Stream stream, final StreamStatus streamStatus) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (StreamStatus.PUBLISHING.equals(streamStatus)) {
mStatusView.setText("RECORDING");
/**
* Filename of the recording is determined.
*/
recordFilename = stream.getRecordName();
return;
} else if (StreamStatus.FAILED.equals(streamStatus)) {
Log.e(TAG, "Can not publish stream " + stream.getName() + " " + streamStatus);
recordFilename = null;
}
mStatusView.setText(streamStatus.toString());
}
});
}
});
ActivityCompat.requestPermissions(StreamRecordingActivity.this, new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA }, PUBLISH_REQUEST_CODE);
}
});
}
@Override
public void onRegistered(Connection connection) {
}
@Override
public void onDisconnection(final Connection connection) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mStartButton.setText(R.string.action_start);
mStartButton.setTag(R.string.action_start);
mStartButton.setEnabled(true);
mStatusView.setText(connection.getStatus());
/**
* After disconnection, download link for the recording of the published stream is displayed, and the recording can be played in the media player of the application.
*/
if (recordFilename != null) {
/**
* Download link is formed.
* Stream recordings are saved to directory WCS_HOME/client/records on the server.
*/
String url = "http://" + uri.getHost() + ":9091/client/records/" + recordFilename;
mRecordedLink.setText(url);
Linkify.addLinks(mRecordedLink, Linkify.WEB_URLS);
MediaController mediaController = new MediaController(StreamRecordingActivity.this);
mediaController.setAnchorView(mRecordedVideoView);
mRecordedVideoView.setMediaController(mediaController);
mRecordedVideoView.setVideoURI(Uri.parse(url));
/**
* Playback of the recording in the media player is started.
*/
mRecordedVideoView.start();
}
}
});
}
});
mStartButton.setEnabled(false);
/**
* Connection to WCS server is established with method Session.connect().
*/
session.connect(new Connection());
SharedPreferences sharedPref = StreamRecordingActivity.this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("wcs_url", mWcsUrlView.getText().toString());
editor.apply();
} else {
mStartButton.setEnabled(false);
/**
* Connection to WCS server is closed with method Session.disconnect().
*/
session.disconnect();
}
View currentFocus = getCurrentFocus();
if (currentFocus != null) {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
});
localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
localRender.setZOrderMediaOverlay(true);
localRenderLayout.setPosition(0, 0, 100, 100);
localRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
localRender.setMirror(true);
localRender.requestLayout();
mRecordedLink = (TextView) findViewById(R.id.recorded_link);
mRecordedVideoView = (VideoView) findViewById(R.id.recorded_video_view);
}
use of android.widget.MediaController in project Android-video-stream-rotation by gradha.
the class HelloInterruptVideoStream method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
video_view_ = (VideoView) findViewById(R.id.surface_view);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
video_view_.setVideoURI(Uri.parse(path));
video_view_.setMediaController(new MediaController(this));
video_view_.requestFocus();
video_view_.start();
}
use of android.widget.MediaController in project AndroidSDK-RecipeBook by gabu.
the class Recipe067 method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.video_view);
// MediaControllerを作って
mMediaController = new MediaController(this);
// MediaControllerセット
mVideoView.setMediaController(mMediaController);
// VideoViewで動画を再生する準備ができた時に
// 呼び出されるリスナー
mVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// 3,4秒でMediaControllerが消えちゃうので
// 常に表示させておきたいんだけど
// showメソッドが期待通りに動作してくれない
// durationは正しく取得できてる。
int duration = mVideoView.getDuration();
mMediaController.show(duration);
// リファレンスを信じて0にしてもダメ
// mMediaController.show(0);
// まぁ気にせず再生スタート!
mVideoView.start();
}
});
}
use of android.widget.MediaController in project wh-app-android by WhiteHouse.
the class VideoPlayerFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mMediaController = new MediaController(view.getContext());
mMediaController.setAnchorView(view);
mSurfaceView.getHolder().addCallback(this);
}
Aggregations