7

下記のコードでビデオが正しく機能しない。これの問題は何でしょうか?

MediaController mediaController = new MediaController(getBaseContext());
mediaController.setAnchorView(videoweb);

Uri video = Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1");
videoweb.setMediaController(mediaController);
videoweb.setVideoURI(video);
videoweb.start();

エラー:

動画を再生
できません申し訳ありませんが、この動画は再生できません。

4

5 に答える 5

6

提供したリンクhttp://www.youtube.com/v/wwI2w2YHkCQ?fs=1は、HTMLページ用です。提供するURIは、 MP4AVIsetVideoURI()などのメディアファイルである必要があります。

VideoViewはHTMLページを解析できません。ビデオファイルのデコードと再生、またはビデオコンテンツのストリーミングのみが可能です(この場合、URIはなどのメディアファイルを指している必要がありますhttp://people.sc.fsu.edu/~jburkardt/data/mp4/cavity_flow_movie.mp4)。ストリーミングまたはプログレッシブダウンロードビデオのVideoViewの使用に関するStackOverflowの質問を参照してください。

YouTubeリンクを開くには、Webviewを使用する必要があります。

于 2012-01-04T11:18:18.917 に答える
2

VideoViewまた、 AndroidがサポートするメディアフォーマットMediaplayerのドキュメントに記載されているフォーマットのみを再生できます。

あなたが提供したYouTubeビデオのリンクはHTMLページ用です。Karthikが述べたようにHTMLページを再生している場合は、を使用することをお勧めしますWebview

String url = "your_youtube_link";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

そのリンクからビデオのみを表示したい場合は、他のすべての詳細をページに残してください。これがYouTubeリンクであるとしますhttp://www.youtube.com/watch?v=ZC7ZOGpM2cU&feature=g-logo&context=G233b464FOAAAAAAABAA

YouTube HTMLページのソースを解析すると、次の部分が表示される場合があります。

<link rel="alternate" type="application/json+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DZC7ZOGpM2cU&amp;format=json" title="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<link rel="alternate" type="text/xml+oembed" href="http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DZC7ZOGpM2cU&amp;format=xml" title="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<meta property="fb:app_id" content="87741124305">
<meta property="og:url" content="http://www.youtube.com/watch?v=ZC7ZOGpM2cU">
<meta property="og:title" content="Bigg Boss 5: Juhi Parmar wins Big Boss season 5">
<meta property="og:description" content="Ntv News: Juhi Parmar wins Bigg Boss 5 - Juhi Parmar wins &#39;Bigg Boss 5&#39;, takes home Rs.1 crore - No kid for now, keen for good work: Juhi Parmar">
<meta property="og:type" content="video">
<meta property="og:image" content="http://i3.ytimg.com/vi/ZC7ZOGpM2cU/hqdefault.jpg">
<meta property="og:video" content="http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&amp;autohide=1">
<meta property="og:video:type" content="application/x-shockwave-flash">
<meta property="og:video:width" content="396">
<meta property="og:video:height" content="297">
<meta property="og:site_name" content="YouTube">

これで、以下を抽出します

<meta property="og:video" content="http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&amp;autohide=1">

この場合、<http://www.youtube.com/v/ZC7ZOGpM2cU?version=3&amp;autohide=1>リンクは全画面表示になります。

于 2012-01-10T13:59:58.057 に答える
1

実際、私が使用しているストリーミングビデオを再生するために

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1")));

しかし、これはあなたのリンクではうまくいかないと思います。試してみてください

mediaplayer.setdataSource("your link").
于 2012-01-10T10:17:35.363 に答える
1

OK、次のコードを試してください。それが動作します。

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.youtube.com/v/wwI2w2YHkCQ?fs=1"));
startActivity(i);
于 2012-01-10T13:34:35.597 に答える
0
private VideoView mVideoView;

@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.main);
        mVideoView = (VideoView) findViewById(R.id.surface_view);
    }

    private void playVideo() {
        try {
            final String path = "http://www.youtube.com/v/wwI2w2YHkCQ?fs=1"

            System.out.println("path  "+path);
            Log.v(TAG, "path: " + path);
            if (path == null || path.length() == 0) {
                Toast.makeText(VideoViewDemo.this, "File URL/path is empty",
                        Toast.LENGTH_LONG).show();
            }
            else {
                System.out.println("else  ");
                // If the path has not changed, just start the media player
                if (path.equals(current) && mVideoView != null) {
                    System.out.println("mVideoView.start()  ");

                    mVideoView.start();
                    mVideoView.requestFocus();
                    return;
                }
                current = path;
                //mVideoView.setVideoPath(getDataSource(path));
                mVideoView.setVideoURI(Uri.parse(path));
                mVideoView.start();
                mVideoView.requestFocus();
            }
        }
        catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);
            if (mVideoView != null) {
                mVideoView.stopPlayback();
            }
        }
    }

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
>
    <EditText android:id="@+id/path"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
            />

    <LinearLayout android:orientation="horizontal"
                  android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
    >
        <ImageButton android:id="@+id/play"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/play"/>

        <ImageButton android:id="@+id/pause"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/pause"/>
        <ImageButton android:id="@+id/reset"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/reset"/>
        <ImageButton android:id="@+id/stop"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/stop"/>
    </LinearLayout>

    <VideoView android:id="@+id/surface_view"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent">
    </VideoView>
</LinearLayout>
于 2012-01-04T11:12:01.193 に答える