我的片段无法播放视频/音频链接

时间:2018-08-24 11:11:22

标签: java android android-fragments

   package com.mixlr.www.oco;

   import android.annotation.SuppressLint;
   import android.net.Uri;
   import android.os.Bundle;
   import android.support.annotation.NonNull;
   import android.support.annotation.Nullable;
   import android.support.v4.app.Fragment;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.media.MediaPlayer;
   import android.widget.MediaController;
   import android.widget.VideoView;

   import static com.mixlr.www.beachradioco.R.layout.fragment_listen;


   public class ListenFragment extends Fragment {

       @Override
       public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                                Bundle savedInstanceState) {
           View rootView = inflater.inflate(fragment_listen,
                   container, false);

           VideoView videoView = VideoView.findViewById(R.id.videoView);
           videoView.setVideoPath("http://edge.mixlr.com/channel/wtrpf");
           videoView.start();


           return inflater.inflate(fragment_listen, null);
       }
   }

我正在尝试播放链接中的剪辑。我在android studio中的片段无法播放视频/音频链接。这个脆弱的代码请帮忙,它的xml文件仅具有视频视图

1 个答案:

答案 0 :(得分:1)

更改代码

来自

View rootView = inflater.inflate(fragment_listen, container, false);

VideoView videoView = VideoView.findViewById(R.id.videoView);
videoView.setVideoPath("http://edge.mixlr.com/channel/wtrpf");
videoView.start();


return inflater.inflate(fragment_listen, null);

收件人

View rootView = inflater.inflate(fragment_listen, container, false);

VideoView videoView = rootView.findViewById(R.id.videoView);
videoView.setVideoPath("http://edge.mixlr.com/channel/wtrpf");
videoView.start();

return rootView;

更新:请确保您在AndroidManifest.xml文件中添加了Internet权限

<uses-permission android:name="android.permission.INTERNET"/>

奖金::您可以添加MediaController来控制播放。这些控件应包括搜索栏,音量控件和播放/暂停按钮。

View rootView = inflater.inflate(fragment_listen, container, false);

VideoView videoView = rootView.findViewById(R.id.videoView);
videoView.setVideoPath("http://edge.mixlr.com/channel/wtrpf");

MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);

videoView.start();

return rootView;