1

I am new in android development. I need to get idea about how to deploy Video/Audio file as a web-service at glass-fish server and then call the web-service from client device (Mobile). Please help me to get very basic idea. I have already run many (simple) applications on server and called them successfully from client device. This time need to call an audio/video file and get it on my client device.

Thanks

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
Mushtaq
  • 29
  • 6

2 Answers2

0

I have already run many (simple) applications on server and called them successfully from client device.

I'm not sure what you are asking. Audio or Video files are trasfered the same way as everything else. You have the same challenges as transfering a "Hello World" String.

If it's the playback you struggle with here is a great media player tutorial. MediaPlayer Tutorial

Valitos
  • 36
  • 3
  • Actually I am new and could not explain ma question clearly. Well, the link you given is just about developing a mediaplaer for android. My question is I want this mediaplayer to run on server. I have to send the audio file playing request from Mobile (Client) device and the server should response. Is there any idea like that? I have run so many simple applications on server and passed arguments from client device and got the resulted values back on my Client device. – Mushtaq May 03 '16 at 01:12
  • Exactly the same i need for a mediaplyer to run on server and I send the song request , server should get song request process it and send back the played contents on mob device. Thanks – Mushtaq May 03 '16 at 01:13
  • Example code for Media player as a service? I have done a bit about how to configure a webservice and how to call it from mobile device. I will that code. My question is can we do the same to install a mediaplayer as a webservice and then call that media player from android device? – Mushtaq May 19 '16 at 05:16
  • Well show me some code of you calling your configured webservice from the mobile device. – Valitos May 22 '16 at 02:02
0

the two Webserver classes are ...

1-

package org.ali.javabrains.business;

import java.util.ArrayList;
import java.util.List;

public class BusinessProductImpl {

List<String> bookList= new ArrayList<String>();
List<String> moviesList= new ArrayList<String>();
List<String> musicList= new ArrayList<String>();

public BusinessProductImpl(){

    bookList.add("swatnama");
    bookList.add("yadona");
    bookList.add("ka ta raghali za ba gul sham");

    musicList.add ("hamayun album1");
    musicList.add ("bkhtayar Khatak");
    musicList.add ("zare sandary");

    moviesList.add("bajrangi bhai jan");
    moviesList.add("Terminator 2");
    moviesList.add("Salam Namasty");
}

public List<String> getProductCategories(){

List<String> categories=new ArrayList<>();
categories.add("books");
categories.add("Movies");
categories.add("Music");
return categories;
}

public List<String> getProducts(String category){
    switch (category.toLowerCase()) {
    case "books":
        return bookList;
    case "music":
        return musicList;
    case "movies":
        return moviesList;
    }
        return null;
    }
public boolean addProduct(String category, String product){

    switch (category.toLowerCase()) {
    case "books":
        bookList.add(product);
        break;
    case "music":
        musicList.add(product);
        break;
    case "movies":
        moviesList.add(product);
        break;
    default:
        return false;
    }
        return true;
}

}

2- .....

package org.ali.javabrains;

import java.util.List;
import org.ali.javabrains.business.BusinessProductImpl;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class ProductCatalog {

BusinessProductImpl BpImpl=new BusinessProductImpl();
@WebMethod
public List<String> getProductCategories(){
return BpImpl.getProductCategories();
}

@WebMethod
public List<String> getProducts(String category){
    return BpImpl.getProducts(category);
}
public boolean addProduct(String category, String product){
    return BpImpl.addProduct(category, product);
}

public int addnumbers(int a, int b){
    return (a+b);
}
public int minusnumbers(int a, int b){
    return (a-b);
}
}  

and the calls from Client device are ...

1-

package com.example.bookwservice;



import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
private static final String
   SOAP_ACTION1="http://javabrains.ali.org/addnumbers";
private static final String METHOD_NAME1="addnumbers";
private static final String 
SOAP_ACTION2="http://javabrains.ali.org/minusnumbers";
private static final String METHOD_NAME2="minusnumbers";
private static final String NAMESPACE="http://javabrains.ali.org/";
private static final String   
URL="http://172.25.181.54:8080/TestWeb/ProductCatalogService";
TextView tv1, tv2, tv3;
EditText et1, et2,et3;
Button bt1, bt2, bt3;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv1=(TextView)findViewById(R.id.textView1);
    tv2=(TextView)findViewById(R.id.textView2);
    tv3=(TextView)findViewById(R.id.textView3);

    et1=(EditText)findViewById(R.id.editText1);
    et2=(EditText)findViewById(R.id.editText2); 
    et3=(EditText)findViewById(R.id.editText3);

    bt1=(Button)findViewById(R.id.button1);
    bt2=(Button)findViewById(R.id.button2);
    bt3=(Button)findViewById(R.id.button3);
    et1.requestFocus();

    bt1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

    SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME1);
    request.addProperty("arg0",et1.getText().toString());
    request.addProperty("arg1",et2.getText().toString());


    SoapSerializationEnvelope soapEnvelope =new 
    SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet=false;
    soapEnvelope.setOutputSoapObject(request);

    AndroidHttpTransport aht=new AndroidHttpTransport(URL);
    try {
        aht.call(SOAP_ACTION1, soapEnvelope);
        SoapPrimitive resultString=
        (SoapPrimitive)soapEnvelope.getResponse();

            et3.setText("" +resultString);

        }

    catch (Exception e){

        e.printStackTrace();
    }
        }});


    bt2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

    SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME2);
    request.addProperty("arg0",et1.getText().toString());
    request.addProperty("arg1",et2.getText().toString());


    SoapSerializationEnvelope soapEnvelope =new 
    SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet=false;
    soapEnvelope.setOutputSoapObject(request);

    AndroidHttpTransport aht=new AndroidHttpTransport(URL);
    try {
        aht.call(SOAP_ACTION2, soapEnvelope);
        SoapPrimitive resultString=

        (SoapPrimitive)soapEnvelope.getResponse();

            et3.setText("" +resultString);

        }

    catch (Exception e){

        e.printStackTrace();
    }
        }});

    bt3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {

                    et1.setText("");
                    et2.setText("");
                    et3.setText("");
                    et1.requestFocus();

                }

            catch (Exception e){

                e.printStackTrace();
            }
                }});

        }

}
Mushtaq
  • 29
  • 6