Open lvjiancong opened 1 year ago
1、我的投屏流地址rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid,用VLC播放正常 2、用Connect-SDK-Android投屏异常:Internal Server Error 3、我的测试代码如下 package com.connectsdk.sampler;
import android.app.AlertDialog; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;
import com.connectsdk.core.MediaInfo; import com.connectsdk.device.ConnectableDevice; import com.connectsdk.device.ConnectableDeviceListener; import com.connectsdk.device.DevicePicker; import com.connectsdk.discovery.CapabilityFilter; import com.connectsdk.discovery.DiscoveryManager; import com.connectsdk.discovery.DiscoveryManagerListener; import com.connectsdk.service.DeviceService; import com.connectsdk.service.capability.MediaControl; import com.connectsdk.service.capability.MediaPlayer; import com.connectsdk.service.capability.VolumeControl; import com.connectsdk.service.command.ServiceCommandError;
import java.util.List;
public class TestActivity extends AppCompatActivity implements DiscoveryManagerListener, View.OnClickListener, ConnectableDeviceListener {
private TextView mTvSearch; private DevicePicker devicePicker; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); CapabilityFilter videoFilter = new CapabilityFilter( MediaPlayer.Play_Video, MediaControl.Any, VolumeControl.Volume_Up_Down ); CapabilityFilter imageCapabilities = new CapabilityFilter( MediaPlayer.Display_Image ); DiscoveryManager.getInstance().setPairingLevel(DiscoveryManager.PairingLevel.ON); DiscoveryManager.getInstance().setCapabilityFilters(videoFilter); DiscoveryManager discoveryManager = DiscoveryManager.getInstance(); discoveryManager.addListener(this); discoveryManager.start(); mTvSearch = findViewById(R.id.tv_search); mTvSearch.setOnClickListener(this); } @Override public void onDeviceAdded(DiscoveryManager manager, ConnectableDevice device) {
// Log.e("TestActivity", "onDeviceAdded"); }
@Override public void onDeviceUpdated(DiscoveryManager manager, ConnectableDevice device) {
// Log.e("TestActivity", "onDeviceUpdated"); }
@Override public void onDeviceRemoved(DiscoveryManager manager, ConnectableDevice device) {
// Log.e("TestActivity", "onDeviceRemoved"); }
@Override public void onDiscoveryFailed(DiscoveryManager manager, ServiceCommandError error) { Log.e("TestActivity", "onDeviceDisconnected"); } @Override public void onClick(View view) { if (view == mTvSearch) { showImage(); } } private ConnectableDevice mDevice;
// String mediaURL = "https://1251542705.vod2.myqcloud.com/4a8d9c67vodtransgzp1251542705/bc0f40875576678020645410808/v.f100820.mp4"; // credit: Blender Foundation/CC By 3.0 // String mediaURL = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"; // credit: Blender Foundation/CC By 3.0 String mediaURL = "rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid"; // credit: Blender Foundation/CC By 3.0 String iconURL = "http://www.connectsdk.com/files/2013/9656/8845/test_image_icon.jpg"; // credit: sintel-durian.deviantart.com String title = "Sintel Trailer"; String description = "Blender Open Movie Project"; String mimeType = "video/"; // audio/ for audio files MediaInfo mediaInfo = new MediaInfo.Builder(mediaURL, mimeType) .setTitle(title) .setDescription(description) .setIcon(iconURL) .build();
MediaPlayer.LaunchListener listener = new MediaPlayer.LaunchListener() { @Override public void onSuccess(MediaPlayer.MediaLaunchObject object) { // save these object references to control media playback
// mLaunchSession = object.launchSession; // mMediaControl = object.mediaControl;
// you will want to enable your media control UI elements here Log.e("TestActivity", "onSuccess"); } @Override public void onError(ServiceCommandError error) { Log.e("TestActivity", "onError = " + error.getMessage()); } }; AdapterView.OnItemClickListener selectDevice = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) { mDevice = (ConnectableDevice) adapter.getItemAtPosition(position); mDevice.addListener(TestActivity.this); mDevice.connect(); devicePicker.pickDevice(mDevice); } }; private void showImage() { devicePicker = new DevicePicker(this); AlertDialog dialog = devicePicker.getPickerDialog("投屏", selectDevice); dialog.show(); } @Override public void onDeviceReady(ConnectableDevice device) { Log.e("TestActivity", "onDeviceReady"); MediaPlayer mediaPlayer = mDevice.getCapability(MediaPlayer.class); if (mediaPlayer != null) { mediaPlayer.playMedia(mediaInfo, false, listener); } else { Log.e("TestActivity", "onDeviceReady else "); } } @Override public void onDeviceDisconnected(ConnectableDevice device) { Log.e("TestActivity", "onDeviceDisconnected"); mDevice.getMediaPlayer().playMedia(mediaInfo, false, listener); } @Override public void onPairingRequired(ConnectableDevice device, DeviceService service, DeviceService.PairingType pairingType) { Log.e("TestActivity", "onPairingRequired"); } @Override public void onCapabilityUpdated(ConnectableDevice device, List<String> added, List<String> removed) { Log.e("TestActivity", "onCapabilityUpdated"); } @Override public void onConnectionFailed(ConnectableDevice device, ServiceCommandError error) { Log.e("TestActivity", "onConnectionFailed"); }
}
我发现是因为DLNAService中的encodeURL()方法会对url进行转换成uri,这个过程出错了,我尝试去掉这个转换过程,直接返回原url,是能够正常投屏成功,这个转换的目的是什么呢,是否其他Service也有类似问题呢?
1、我的投屏流地址rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid,用VLC播放正常 2、用Connect-SDK-Android投屏异常:Internal Server Error 3、我的测试代码如下 package com.connectsdk.sampler;
import android.app.AlertDialog; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;
import com.connectsdk.core.MediaInfo; import com.connectsdk.device.ConnectableDevice; import com.connectsdk.device.ConnectableDeviceListener; import com.connectsdk.device.DevicePicker; import com.connectsdk.discovery.CapabilityFilter; import com.connectsdk.discovery.DiscoveryManager; import com.connectsdk.discovery.DiscoveryManagerListener; import com.connectsdk.service.DeviceService; import com.connectsdk.service.capability.MediaControl; import com.connectsdk.service.capability.MediaPlayer; import com.connectsdk.service.capability.VolumeControl; import com.connectsdk.service.command.ServiceCommandError;
import java.util.List;
public class TestActivity extends AppCompatActivity implements DiscoveryManagerListener, View.OnClickListener, ConnectableDeviceListener {
// Log.e("TestActivity", "onDeviceAdded"); }
// Log.e("TestActivity", "onDeviceUpdated"); }
// Log.e("TestActivity", "onDeviceRemoved"); }
// String mediaURL = "https://1251542705.vod2.myqcloud.com/4a8d9c67vodtransgzp1251542705/bc0f40875576678020645410808/v.f100820.mp4"; // credit: Blender Foundation/CC By 3.0 // String mediaURL = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"; // credit: Blender Foundation/CC By 3.0 String mediaURL = "rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid"; // credit: Blender Foundation/CC By 3.0 String iconURL = "http://www.connectsdk.com/files/2013/9656/8845/test_image_icon.jpg"; // credit: sintel-durian.deviantart.com String title = "Sintel Trailer"; String description = "Blender Open Movie Project"; String mimeType = "video/"; // audio/ for audio files MediaInfo mediaInfo = new MediaInfo.Builder(mediaURL, mimeType) .setTitle(title) .setDescription(description) .setIcon(iconURL) .build();
// mLaunchSession = object.launchSession; // mMediaControl = object.mediaControl;
}