直播VideoView | Android的

时间:2016-10-01 17:23:45

标签: android live-streaming http-live-streaming youtube-livestreaming-api

我一直在尝试在我的Android应用程序中播放/流式播放来自youtube的实时视频,我尝试了很多示例和教程但没有工作。我尝试过的一些示例和教程:

String path = "http://www.mediaserveryoururl.com/sample.3gp";
         // Create a new media player and set the listeners
         MediaPlayer mMediaPlayer = new MediaPlayer();
         try {
         mMediaPlayer.setDataSource(path);
         } catch (IOException e) {
         e.printStackTrace();
         }
         mMediaPlayer.setDisplay(holder);
         try {
         mMediaPlayer.prepare();
         } catch (IOException e) {
         e.printStackTrace();
         }
         mMediaPlayer.setOnBufferingUpdateListener((MediaPlayer.OnBufferingUpdateListener) this);
         mMediaPlayer.setOnCompletionListener((MediaPlayer.OnCompletionListener) this);
         mMediaPlayer.setOnPreparedListener((MediaPlayer.OnPreparedListener) this);
         mMediaPlayer.setOnVideoSizeChangedListener((MediaPlayer.OnVideoSizeChangedListener) this);
         mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

String SrcPath="http://akamedia2.lsops.net/live/smil:cnbc_en.smil/playlist.m3u8";
videoView = new VideoView(this);
         videoView.setVideoURI(Uri.parse(SrcPath));
         setContentView(videoView);
         videoView.setMediaController(new MediaController(this));

         videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override public void onPrepared(MediaPlayer mediaPlayer) {
        videoView.start();
        }
        });

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
        MainActivity.this.finish();
        }
        });

         MediaController mc = new MediaController(MainActivity.this);
         videoView.setMediaController(mc);
         String str = "VIDEO URL";
         //        Log.d("url: "+str);
         Uri uri = Uri.parse(str);

         videoView.setVideoURI(uri);

         videoView.requestFocus();
         videoView.start();

 Intent videoIntent = YouTubeStandalonePlayer.createVideoIntent(this, YT_KEY, VIDEO_ID, 0, true, false);

 startActivityForResult(videoIntent, REQ_PLAYER_CODE);

 }

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
 if (requestCode == REQ_PLAYER_CODE && resultCode != RESULT_OK) {
 YouTubeInitializationResult errorReason = YouTubeStandalonePlayer.getReturnedInitializationResult(data);
 if (errorReason.isUserRecoverableError()) {
 errorReason.getErrorDialog(this, 0).show();
 } else {
 String errorMessage = String.format("PLAYER ERROR!!", errorReason.toString());
 Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
 }
 }

MediaController mediaController= new MediaController(this);
     mediaController.setAnchorView(videoView);
      Uri uri=Uri.parse("rtsp://r9---sn-a5m7lner.googlevideo.com/Cj0LENy73wIaNAmk3cJBg-iaXhMYDSANFC0WBO9XMOCoAUIASARgg9bxwYT2uqRXigELOXRFUGFqeTlWa3cM/405DAA0B57E13BF99ACA242EE60CC9BAC7BE995D.B7E85376CB9B68F978DFB5DA70650545DDA18272/yt6/1/video.3gp");
     videoView.setMediaController(mediaController);
     videoView.setVideoURI(uri);
     videoView.requestFocus();
     videoView.start();

虽然有些示例看起来不错,但唯一出现的问题是"无法播放此视频"

请帮助我,我真的很困惑,并尝试了各种解决方案。任何帮助,将不胜感激。 谢谢!

0 个答案:

没有答案