Sikandar Ejaz
Sikandar Ejaz

Reputation: 53

Playing Videos in Android Application without Youtube API

I am making an application in which I want to play online videos from sites like youtube, daily motion, vimeo, etc. The problem I am facing is that when I try to play videos from daily motion, the videos are not playing and the player replies with an error: "There was a problem with the network". My internet connection is working fine.

My main activity file is here:

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);
            }
        });
    }
}

Manifest file is this..

<?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>

Please tell me what mistake I am making.

Upvotes: 3

Views: 3352

Answers (2)

Simas
Simas

Reputation: 44118

Are you trying to play non-youtube videos in youtube? I don't think that will work.

Your code works fine with normal youtube links like http://youtube.com/watch?v=xxxxxxxxxxx

To stream videos not from youtube, you should probably use MediaPlayer. Here's a simple example.

EDIT:

This is a new question but, oh well. If your country blocks youtube, that means you need to use a proxy to bypass that. There are some unofficial ways to do that, like this.

However do note that using a proxy will limit your bandwidth and the streaming might lose a lot of quality. Unfortunately you can't avoid this :-(

Upvotes: 2

Izzo32
Izzo32

Reputation: 179

You can use VideoView, here's a tut, check it out

Upvotes: 0

Related Questions