开发者

Can not play video from youtube

Hi I am new to android and I am trying to play youtube video using this code but I am not getting any result even not getting error.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Uri uri = Uri.parse("http://www.youtube.com/watch?v=hPUGNCIozp0");
    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
    startActivity(intent);
}

my XML file

<?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"
   android:background="@drawable/back"
   android:weightSum="1">
</LinearLayout>

my Manifest开发者_如何学C file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vdemo" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".VDemoActivity" 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>


Hey here it working fine. I checked the code. I think check for internet permission. After execution you are able get the options like internet or youtube or not.


Are you sure you have add permissoin in AndroidManifest.xml

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜