qrtt1

Untitled

Aug 7th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.android.media;
  19.  
  20. import java.io.BufferedReader;
  21. import java.io.FileReader;
  22. import java.io.IOException;
  23. import java.net.MalformedURLException;
  24. import java.net.URL;
  25.  
  26. import android.app.Activity;
  27. import android.content.pm.ActivityInfo;
  28. import android.media.MediaPlayer;
  29. import android.net.Uri;
  30. import android.os.Bundle;
  31. import android.os.Environment;
  32. import android.util.Log;
  33. import android.widget.MediaController;
  34. import android.widget.VideoView;
  35.  
  36. public class VideoViewDemo extends Activity implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener {
  37. public static final String TAG = "VideoPlayer";
  38. private VideoView mVideoView;
  39. private Uri mUri;
  40. private int mPositionWhenPaused = -1;
  41.  
  42. private MediaController mMediaController;
  43.  
  44. /** Called when the activity is first created. */
  45. @Override
  46. public void onCreate(Bundle savedInstanceState) {
  47. super.onCreate(savedInstanceState);
  48.  
  49. setContentView(R.layout.main);
  50.  
  51. // Set the screen to landscape.
  52. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  53.  
  54. mVideoView = (VideoView) findViewById(R.id.video_view);
  55.  
  56. // Video file
  57. // mUri =
  58. // Uri.parse("http://s3-ap-southeast-1.amazonaws.com/muzee.sg.tmp/albert/she_stream_20120807.asf");
  59. // mUri = Uri.parse("mmsh://muzee21.serverroom.us/muzeeshe");
  60. // mUri = Uri.parse("mmsh://38.96.148.89/muzeeshe");
  61. // mUri = Uri.parse("rtsp://58.200.131.2/CCTV-7");
  62.  
  63. // mUri = Uri.parse("mmst://mediasrv2.iptv.xmg.com.cn/tvhaixia");
  64. // Create media controller
  65. mMediaController = new MediaController(this);
  66. mVideoView.setMediaController(mMediaController);
  67. }
  68.  
  69. private String getUrl() {
  70. return "http://live-cdn.smgbb.tv/channels/214/400.flv/live/livestream";
  71. }
  72.  
  73. public void onStart() {
  74. // Play Video
  75. String url = getUrl();
  76. Log.i("AMAM", "get-url: " + url);
  77. mUri = Uri.parse(url);
  78.  
  79. mVideoView.setVideoURI(mUri);
  80. Log.i("AMAMAM", "mUri: " + mUri);
  81. mVideoView.start();
  82.  
  83. super.onStart();
  84. }
  85.  
  86. public void onPause() {
  87. // Stop video when the activity is pause.
  88. mPositionWhenPaused = mVideoView.getCurrentPosition();
  89. mVideoView.stopPlayback();
  90. Log.d(TAG, "OnStop: mPositionWhenPaused = " + mPositionWhenPaused);
  91. Log.d(TAG, "OnStop: getDuration = " + mVideoView.getDuration());
  92.  
  93. super.onPause();
  94. }
  95.  
  96. public void onResume() {
  97. // Resume video player
  98. if (mPositionWhenPaused >= 0) {
  99. mVideoView.seekTo(mPositionWhenPaused);
  100. mPositionWhenPaused = -1;
  101. }
  102.  
  103. super.onResume();
  104. }
  105.  
  106. public boolean onError(MediaPlayer player, int arg1, int arg2) {
  107. return false;
  108. }
  109.  
  110. public void onCompletion(MediaPlayer mp) {
  111. this.finish();
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment