我正在为服务器上的直播视频编写应用程序。我正在使用Vitamio库。不幸的是,应用程序与服务器连接,但不显示任何视频。服务器正确发送数据,问题出在我的应用程序中。你能告诉我,我做错了什么?
应用:
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
public class MainActivity extends Activity {
private String PatchToUrl = "http://192.168.1.110:8081";
//private String PatchToUrl = "";
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!LibsChecker.checkVitamioLibs(this)) {
return;
}
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
if (PatchToUrl == "") {
Toast.makeText(this, "URL address is empty!", Toast.LENGTH_LONG).show();
return;
}else{
//mVideoView.setVideoURI(Uri.parse(URLstring)
videoView.setVideoURI(Uri.parse(PatchToUrl));
//videoView.setVideoPath(PatchToUrl);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setPlaybackSpeed(1.0f);
}
});
}
}
public void onBtnStart(View view){
if(!TextUtils.isEmpty(PatchToUrl)){
videoView.setVideoPath(PatchToUrl);
}
}
public void onBtnStop(View view){
if (!TextUtils.isEmpty(PatchToUrl)){
videoView.pause();
}
}
public void openVideo(View view){
videoView.setVideoPath(PatchToUrl);
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mforyt.myapplication">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden"/>
</application>
</manifest>