Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.android.media;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import android.app.Activity;
- import android.content.pm.ActivityInfo;
- import android.media.MediaPlayer;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Environment;
- import android.util.Log;
- import android.widget.MediaController;
- import android.widget.VideoView;
- public class VideoViewDemo extends Activity implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener {
- public static final String TAG = "VideoPlayer";
- private VideoView mVideoView;
- private Uri mUri;
- private int mPositionWhenPaused = -1;
- private MediaController mMediaController;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // Set the screen to landscape.
- this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- mVideoView = (VideoView) findViewById(R.id.video_view);
- // Video file
- // mUri =
- // Uri.parse("http://s3-ap-southeast-1.amazonaws.com/muzee.sg.tmp/albert/she_stream_20120807.asf");
- // mUri = Uri.parse("mmsh://muzee21.serverroom.us/muzeeshe");
- // mUri = Uri.parse("mmsh://38.96.148.89/muzeeshe");
- // mUri = Uri.parse("rtsp://58.200.131.2/CCTV-7");
- // mUri = Uri.parse("mmst://mediasrv2.iptv.xmg.com.cn/tvhaixia");
- // Create media controller
- mMediaController = new MediaController(this);
- mVideoView.setMediaController(mMediaController);
- }
- private String getUrl() {
- return "http://live-cdn.smgbb.tv/channels/214/400.flv/live/livestream";
- }
- public void onStart() {
- // Play Video
- String url = getUrl();
- Log.i("AMAM", "get-url: " + url);
- mUri = Uri.parse(url);
- mVideoView.setVideoURI(mUri);
- Log.i("AMAMAM", "mUri: " + mUri);
- mVideoView.start();
- super.onStart();
- }
- public void onPause() {
- // Stop video when the activity is pause.
- mPositionWhenPaused = mVideoView.getCurrentPosition();
- mVideoView.stopPlayback();
- Log.d(TAG, "OnStop: mPositionWhenPaused = " + mPositionWhenPaused);
- Log.d(TAG, "OnStop: getDuration = " + mVideoView.getDuration());
- super.onPause();
- }
- public void onResume() {
- // Resume video player
- if (mPositionWhenPaused >= 0) {
- mVideoView.seekTo(mPositionWhenPaused);
- mPositionWhenPaused = -1;
- }
- super.onResume();
- }
- public boolean onError(MediaPlayer player, int arg1, int arg2) {
- return false;
- }
- public void onCompletion(MediaPlayer mp) {
- this.finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment