我是android开发的新手。我需要了解如何在玻璃鱼服务器上将视频/音频文件部署为Web服务,然后从客户端设备(Mobile)调用Web服务。请帮助我获得非常基本的想法。我已经在服务器上运行了许多(简单)应用程序,并从客户端设备成功调用它们。这次需要调用音频/视频文件并将其放在我的客户端设备上。
谢谢
答案 0 :(得分:0)
我已经在服务器上运行了许多(简单)应用程序并进行了调用 他们成功地从客户端设备。
我不确定你在问什么。音频或视频文件的转换方式与其他所有文件相同。您遇到与转移“Hello World”字符串相同的挑战。
如果这是你在这里努力的回放是一个很棒的媒体播放器教程。 MediaPlayer Tutorial
答案 1 :(得分:0)
两个Webserver类是......
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);
}
}
来自客户端设备的呼叫是......
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();
}
}});
}
}