Soru & Cevap

Webtv Yapmak istiyorum yardım ...

22.02.2015 - 05:56

Merhaba Arkadaşlar;

Çalışmakta olduğum üniversitenin webtv test yayınına başladık .

Youtube üzerinden live streming yapmaktayım  bunu androidte uygulama olarak sunmak istiyorum ve bunu videoview mantıgıyla nasıl eklerım kaynak varmıdır.

Yardımlarınızı bekliyorum teşekkürler.

4 Görüntülenme

2 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-31404-1421919825.png
muhcob
22.02.2015 - 11:19

Aşağıdaki örnek işini görecektir.

MainActivity.java

[code]package com.muhammed.tv;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends Activity{
    private ProgressBar pBar;
    private Activity activity;
    private String mimeType;
    private String encoding;
    private WebView wv;
    private String html;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setWindowSettings();
        setContentView(R.layout.main);
        initViews();
        setWebViewSettings();
        html = getHTML();
        wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
        activity = this;
        wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                activity.setProgress(progress * 100);
                {
                    if(progress < 100 && pBar.getVisibility() == ProgressBar.GONE){
                        pBar.setVisibility(ProgressBar.VISIBLE);

                    }
                    pBar.setProgress(progress);
                    if(progress == 100) {
                        pBar.setVisibility(ProgressBar.GONE);

                    }
                }
            }
        });
        wv.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_LONG).show();
            }
        });
        wv.setDownloadListener(new DownloadListener()
        {

            public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength)
            {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                startActivity(intent);
            }


        });
    }

    private void setWebViewSettings(){
        WebSettings webSettings = wv.getSettings();
        webSettings.setBuiltInZoomControls(true);
        webSettings.setJavaScriptEnabled(true);
        mimeType = "text/html";
        encoding = "UTF-8";
    }

    private void initViews(){
        pBar = (ProgressBar) findViewById(R.id.pB4);
        wv = (WebView) findViewById(R.id.webVie1);
    }

    private void setWindowSettings(){
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
    }

    private String getHTML() {
        String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
                + "rWE_80SNv8w"
                + "?fs=0\" frameborder=\"0\">\n"
                + "</iframe>\n";
        return html;
    }


   public void onPause()
    {
        super.onPause();
        System.exit(0);
    }
}[/code]

main.xml

[code]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/page_buttons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >


    </LinearLayout>

    <WebView
        android:id="@+id/webVie1"
        android:layout_width="316dp"
        android:layout_height="392dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_weight="0.99" />

    <ProgressBar
        android:id="@+id/pB4"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/> />
</LinearLayout>

[/code]

AndroidManifest.xml

[code]<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.muhammed.tv" >

    <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=".MainActivity"
            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>[/code]

Profile picture for user ulasocal
ulasocal
22.02.2015 - 06:11

Yayın youtube üzerinden alınacaksa aşağıdaki gibi olmalı

 

[code]


String video= "<table bgcolor=\"#666666\"><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/lBMMTeuJ_UQ?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/BZMkY3y7nM0?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td></table>"; mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setPluginState(PluginState.ON); mWebView.getSettings().setPluginsEnabled(true); //mWebView.loadDataWithBaseURL(null,load,"text/html","UTF-8",null); mWebView.loadData(video,"text/html","UTF-8");
 

[/code]

Nurullah YILMAZ
22.02.2015 - 06:19
Örnek bir boş proje eklemeniz mümkünmüdür acaba henüz beginner seviyedeyim :(