3

我正在制作一个应用程序,我想在其中播放来自 youtube、daily motion、vimeo 等网站的在线视频。我面临的问题是,当我尝试播放日常动作中的视频时,视频没有播放,播放器回复错误:“网络出现问题”。我的互联网连接工作正常。

我的主要活动文件在这里:

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;


public class Main extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);

        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String video_path = "http://tune.pk/player/embed_player.php?vid=4240467";
                Uri uri = Uri.parse(video_path);
                uri = Uri.parse("vnd.youtube:"  + uri.getQueryParameter("v"));

                Intent intent = new Intent(Intent.ACTION_VIEW , uri);
                startActivity(intent);
            }
        });
    }
}

清单文件是这个..

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.solutionproviders.videotest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.solutionproviders.videotest.Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

请告诉我我犯了什么错误。

4

2 回答 2

2

您是否尝试在 youtube 中播放非 youtube 视频?我认为这行不通。

您的代码适用于普通的 youtube 链接,例如http://youtube.com/watch?v=xxxxxxxxxxx

要流式传输不是来自 youtube 的视频,您可能应该使用 MediaPlayer。这是一个简单的例子

编辑:

这是一个新问题,但是,哦,好吧。如果您所在的国家/地区屏蔽了 youtube,则意味着您需要使用代理来绕过它。有一些非官方的方法可以做到这一点,比如 this

但是请注意,使用代理会限制您的带宽,并且流媒体可能会损失很多质量。不幸的是,您无法避免这种情况:-(

于 2014-07-26T13:44:52.843 回答
0

你可以使用VideoView,这里有一个啧啧,看看

于 2014-07-26T13:48:37.817 回答