Android片段 - 无法播放此视频

时间:2015-12-14 12:00:46

标签: java android android-fragments video

我想通过在android中使用片段来播放网站上的视频。但是,当我运行应用程序时,错误显示说明

  

无法播放此视频

网址有效且编码没有错误。有人能帮助我吗?

VideoFragment.java

public class VideoFragment extends Fragment {
VideoView videoview;

String VideoURL="https://www.youtube.com/watch?v=pzWfjOaAbcE";

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

View  v = inflater.inflate(R.layout.videoview_fragment, container, false);
VideoView videoView=(VideoView)v.findViewById(R.id.VideoView);

MediaPlayer player = MediaPlayer.create(getActivity(), Uri.parse(VideoURL));


Uri video = Uri.parse(VideoURL);


MediaController mediaController = new MediaController(getActivity());
mediaController.setAnchorView(videoView);
    videoView.setVideoURI(video);
    videoView.requestFocus();
    videoView.setMediaController(mediaController);
    videoView.start();
return  v;
}}

videoview_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <VideoView
    android:id="@+id/VideoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />
</LinearLayout>

logcat的:

12-14 19:57:08.948: E/MediaPlayer-JNI(24690): QCMediaPlayer mediaplayer NOT present
12-14 19:57:08.948: D/MediaPlayer(24690): Couldn't open file on client side, trying server side
12-14 19:57:08.953: D/MediaHTTPConnection(24690): filterOutInternalHeaders: key=User-Agent, val= SonyD6503 Build/23.4.A.1.232 stagefright/1.2 (Linux;Android 5.1.1)
12-14 19:57:08.953: D/MediaHTTPConnection(24690): filterOutInternalHeaders: key=x-wap-profile, val= http://uaprof.sonymobile.com/D6503R2321.xml
12-14 19:57:08.953: D/MediaHTTPConnection(24690): proxy null port 0
12-14 19:57:10.072: E/MediaPlayer(24690): error (1, -2147483648)
12-14 19:57:10.073: D/MediaPlayer(24690): create failed:
12-14 19:57:10.073: D/MediaPlayer(24690): java.io.IOException: Prepare failed.: status=0x1
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.media.MediaPlayer._prepare(Native Method)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.media.MediaPlayer.prepare(MediaPlayer.java:1188)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.media.MediaPlayer.create(MediaPlayer.java:881)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.media.MediaPlayer.create(MediaPlayer.java:854)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.media.MediaPlayer.create(MediaPlayer.java:833)
12-14 19:57:10.073: D/MediaPlayer(24690):   at com.example.eventstory.VideoFragment.onCreateView(VideoFragment.java:25)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.Fragment.performCreateView(Fragment.java:2053)
 12-14 19:57:10.073: D/MediaPlayer(24690):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.BackStackRecord.run(BackStackRecord.java:834)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.os.Handler.handleCallback(Handler.java:739)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.os.Handler.dispatchMessage(Handler.java:95)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.os.Looper.loop(Looper.java:211)
12-14 19:57:10.073: D/MediaPlayer(24690):   at android.app.ActivityThread.main(ActivityThread.java:5373)
12-14 19:57:10.073: D/MediaPlayer(24690):   at java.lang.reflect.Method.invoke(Native Method)
12-14 19:57:10.073: D/MediaPlayer(24690):   at java.lang.reflect.Method.invoke(Method.java:372)
12-14 19:57:10.073: D/MediaPlayer(24690):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
12-14 19:57:10.073: D/MediaPlayer(24690):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
12-14 19:57:10.093: I/Choreographer(24690): Skipped 68 frames!  The application may be doing too much work on its main thread.
12-14 19:57:10.126: I/VideoView(24690): Open Video
12-14 19:57:10.129: E/MediaPlayer-JNI(24690): QCMediaPlayer mediaplayer NOT present
 12-14 19:57:10.132: I/VideoView(24690): SetDataSource
 12-14 19:57:10.133: D/MediaPlayer(24690): Couldn't open file on client side, trying server side
 12-14 19:57:10.139: D/MediaHTTPConnection(24690): filterOutInternalHeaders: key=User-Agent, val= SonyD6503 Build/23.4.A.1.232 stagefright/1.2 (Linux;Android 5.1.1)
 12-14 19:57:10.139: D/MediaHTTPConnection(24690): filterOutInternalHeaders: key=x-wap-profile, val= http://uaprof.sonymobile.com/D6503R2321.xml
 12-14 19:57:10.140: D/MediaHTTPConnection(24690): proxy null port 0

2 个答案:

答案 0 :(得分:2)

您无法在youtube上播放videoView个网址,请使用sdk YOUTUBE API Player

答案 1 :(得分:0)

以简单的方式玩: -

String path1="https://www.youtube.com/watch?v=pzWfjOaAbcE";

Uri uri=Uri.parse(path1);

VideoView video=(VideoView)v.findViewById(R.id.VideoView01);
video.setVideoURI(uri);
video.start();