3

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.

J.J.
  • 1,128
  • 2
  • 23
  • 62
Sikandar Ejaz
  • 53
  • 3
  • 9

2 Answers2

2

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 :-(

Community
  • 1
  • 1
Simas
  • 43,548
  • 10
  • 88
  • 116
  • Right, actually youtube is blocked in Pakistan, that is why I am using links from dailymotion. any possible way to make changes in this code and play videos? – Sikandar Ejaz Jul 26 '14 at 13:47
  • @SikanderEjaz updated. But please don't ask multiple questions :-) To stream from DailyMotion follow my first link. – Simas Jul 26 '14 at 13:55
0

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

Izzo32
  • 179
  • 1
  • 4
  • 16
  • 1
    for using VideoView, I have to out the videos in the raw folder and if I go on adding all videos in raw folder then the size of the application will be increased, that will not be acceptable in the market. – Sikandar Ejaz Jul 26 '14 at 13:51
  • You can use VideoView for streaming media. – Mike M. Jul 26 '14 at 13:59
  • Just to be clear, @SikanderEjaz, VideoView is pretty much just a MediaPlayer and a SurfaceView packaged together, so this is the way to go, if you want to keep it simple. – Mike M. Jul 26 '14 at 14:08
  • Fine, I will use the VideoView but tell me where to put the url of the video? In VideoView we give the path of the video that is available in the raw folder. – Sikandar Ejaz Jul 26 '14 at 15:00
  • @SikanderEjaz Check this [link](http://stackoverflow.com/questions/17366378/how-to-play-a-video-from-url-using-videoview-smoothly) – Izzo32 Jul 27 '14 at 15:21