05-2417:17:47.3352444724478 D EventBusActivity: 2447805-2417:17:48.3412444724478 D EventBusActivity: this is first message ! onEventBackground thread:2447805-2417:17:48.3412444724498 D EventBusActivity: this is first message ! onEventAsync thread:2449805-2417:17:48.3422444724447 D EventBusActivity: this is first message ! onEventMain thread:2444705-2417:17:48.3422444724447 D EventBusActivity: this is first message ! onEventMainOrdered thread:2444705-2417:17:48.3442444724478 D EventBusActivity: this is first message ! onEventPosting thread:24478
/**
* Start an image request using the specified path. This is a convenience method for calling
* {@link #load(Uri)}.
* <p>
* This path may be a remote URL, file resource (prefixed with {@code file:}), content resource
* (prefixed with {@code content:}), or android resource (prefixed with {@code
* android.resource:}.
* <p>
* Passing {@code null} as a {@code path} will not trigger any request but will set a
* placeholder, if one is specified.
*
* @see #load(Uri)
* @see #load(File)
* @see #load(int)
* @throws IllegalArgumentException if {@code path} is empty or blank string.
*/publicRequestCreatorload(String path){if(path ==null){returnnewRequestCreator(this,null,0);}if(path.trim().length()==0){thrownewIllegalArgumentException("Path must not be empty.");}returnload(Uri.parse(path));}
Transformation 这就是Picasso的一个非常强大的功能了,它允许你在load图片 -> into ImageView 中间这个过成对图片做一系列的变换。比如你要做图片高斯模糊、添加圆角、做度灰处理、圆形图片等等都可以通过Transformation来完成。
来看一个高斯模糊的例子:
1,首先定义一个转换器继承 Transformation
publicstaticclassBlurTransformationimplementsTransformation{RenderScript rs;publicBlurTransformation(Context context){super();
rs =RenderScript.create(context);}@OverridepublicBitmaptransform(Bitmap bitmap){// Create another bitmap that will hold the results of the filter.Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888,true);// Allocate memory for Renderscript to work withAllocation input =Allocation.createFromBitmap(rs, blurredBitmap,Allocation.MipmapControl.MIPMAP_FULL,Allocation.USAGE_SHARED);Allocation output =Allocation.createTyped(rs, input.getType());// Load up an instance of the specific script that we want to use.ScriptIntrinsicBlur script =ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
script.setInput(input);// Set the blur radius
script.setRadius(25);// Start the ScriptIntrinisicBlur
script.forEach(output);// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();return blurredBitmap;}@OverridepublicStringkey(){return"blur";}}
LRU memory cache of 15% the available application RAM
Disk cache of 2% storage space up to 50MB but no less than 5MB. (Note: this is only
available on API 14+ <em>or</em> if you are using a standalone library that provides a disk cache on all API levels like OkHttp)
Three download threads for disk and network access.
/** Describes where the image was loaded from. */publicenumLoadedFrom{MEMORY(Color.GREEN),DISK(Color.BLUE),NETWORK(Color.RED);finalint debugColor;privateLoadedFrom(int debugColor){this.debugColor = debugColor;}}
/**
* Created by zhouwei on 17/2/26.
*/publicclassCustomDownloaderimplementsDownloader{@OverridepublicResponseload(Uri uri,int networkPolicy)throwsIOException{returnnull;}@Overridepublicvoidshutdown(){}}
/**
* Set the global instance returned from {@link #with}.
* <p>
* This method must be called before any calls to {@link #with} and may only be called once.
*/publicstaticvoidsetSingletonInstance(Picasso picasso){synchronized(Picasso.class){if(singleton !=null){thrownewIllegalStateException("Singleton instance already exists.");}
singleton = picasso;}}
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
public AcceptThread() {
// Use a temporary object that is later assigned to mmServerSocket,
// because mmServerSocket is final
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app’s UUID string, also used by the client code
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) { }
mmServerSocket = tmp;
}
public void run() {
BluetoothSocket socket = null;
// Keep listening until exception occurs or a socket is returned
while (true) {
try {
socket = mmServerSocket.accept();
} catch (IOException e) {
break;
}
// If a connection was accepted
if (socket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(socket);
mmServerSocket.close();
break;
}
}
}
/** Will cancel the listening socket, and cause the thread to finish */
public void cancel() {
try {
mmServerSocket.close();
} catch (IOException e) { }
}
}
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp = null;
mmDevice = device;
// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app’s UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket = tmp;
}
public void run() {
// Cancel discovery because it will slow down the connection
mBluetoothAdapter.cancelDiscovery();
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(mmSocket);
}
/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
private class ConnectedThread extends Thread {
private final BluetoothSocket mmSocket;
private final InputStream mmInStream;
private final OutputStream mmOutStream;
// Get the input and output streams, using temp objects because
// member streams are final
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) { }
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public void run() {
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes; // bytes returned from read()
// Keep listening to the InputStream until an exception occurs
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
break;
}
}
}
/* Call this from the main Activity to send data to the remote device */
public void write(byte[] bytes) {
try {
mmOutStream.write(bytes);
} catch (IOException e) { }
}
/* Call this from the main Activity to shutdown the connection */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
通过上面的讨论,可以确定地说,Vitamio是一个强大的多平台库(ios and android)。通过使用Vitamio库 能播放多种类型的视频格式和协议如RTMP, RTSP, HTTP Live, and HTTP渐进式流协议。另外一个很好的功能是,vitamio支持字幕和多音轨的播放。Vitamio的唯一的缺点是,它不是完全的开源。您可能需要购买许可证来使用它。希望这会有所帮助。通过Facebook, Google+ and Twitter来联系我们获取更多更新。