我正在制作一个应用程序,我想在其中播放来自 youtube、daily motion、vimeo 等网站的在线视频。我面临的问题是,当我尝试播放来自 daily motion 的视频时,视频没有播放并且玩家回复错误:“网络出现问题”。我的互联网连接工作正常。
我的主要 Activity 文件在这里:
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);
}
});
}
}
list 文件是这个..
<?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>
请告诉我我犯了什么错误。
最佳答案
您是否尝试在 YouTube 中播放非 YouTube 视频?我认为这行不通。
您的代码适用于正常的 youtube 链接,例如 http://youtube.com/watch?v=xxxxxxxxxxx
要流式传输不是来自 youtube 的视频,您可能应该使用 MediaPlayer。这是一个简单的 example .
编辑:
这是一个新问题,但是,好吧。如果您所在的国家/地区阻止 youtube,则意味着您需要使用代理来绕过它。有一些非官方的方法可以做到这一点,like this .
但是请注意,使用代理会限制您的带宽并且流式传输可能会降低很多质量。不幸的是你无法避免这个:-(
关于android - 在没有 Youtube API 的情况下在 Android 应用程序中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24971459/