How to show installed music players options in iOS? - ios

I am doing a project in xamarin.
I exactly needed a popup that shows all the music apps installed in my phone on a button click, so user can select anyone of them and play music independently.
I am able to do this in android with music intent.
This is like I want to play an mp3 file and I tapped on a button. The iOS system shows all the available music in the sheet and by choosing one of them I can play that mp3 file.
Music intent ios

First you declare an interface to openApp:
public interface IOpenAppService
{
Task<bool> Launch(string stringUri);
}
then, in your customRenderer:
[assembly: Xamarin.Forms.Dependency(typeof(OpenAppService))]
namespace OpenAppLaunch.iOS
{
public class OpenAppService : IOpenAppService
{
public Task<bool> Launch(string stringUri)
{
try
{
NSUrl request = new NSUrl(stringUrl);
bool isOpened = UIApplication.SharedApplication.OpenUrl(stringUrl);
if (isOpened == false)
UIApplication.SharedApplication.OpenUrl(new NSUrl(stringUrl));
return Task.FromResult(true);
}
catch (Exception ex)
{
Debug.WriteLine("Cannot open url: {0}, Error: {1}", request.AbsoluteString, ex.Message);
var alertView = new UIAlertView("Error", ex.Message, null, "OK", null);
alertView.Show();
return Task.FromResult(false);
}
}
}
You can use it by calling OpenAppService.Launch("skype://");

Related

Xamarin In App Billing Component Not Connecting To Google Play

I have went through the Xamarin IAB 'tutorial' on it's Component page. I installed the component and Google Play Billing Lib into my app, published my apk to Google Play Dev Console in Alpha and added products on the Dev Console to the app. However, when I try to test the app on a phone, anytime I click on any of the purchase buttons nothing happens. The buttons themselves worked fine I have tested them by pushing other notifications, changing colors, etc. They work with everything else, but when it comes to purchasing nothing happens, no pop-ups, no buffering or attempt to connection, literally nothing. I think my app never connects to Google Play, and I have no idea why.
My Main Activity
private InAppBillingServiceConnection _serviceConnection;
private string publicKey = "my public key";
private IList<Product> _products;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Establish Connection to Google Play Store
_serviceConnection = new InAppBillingServiceConnection(this, publicKey);
_serviceConnection.OnConnected += async () =>
{
// Load available products and any purchases
await RequestProducts();
};
// Attempt to connect to the service
_serviceConnection.Connect();
IAPHelper.Instance.Initalize(_products, _serviceConnection);
var g = new Game1();
SetContentView(g.Services.GetService<View>());
g.Run();
}
// Request a list of available products that the user can purchase by providing alist of
protected async Task RequestProducts()
{
_products = await _serviceConnection.BillingHandler.QueryInventoryAsync(new List<string>{
ReservedTestProductIDs.Purchased,
ReservedTestProductIDs.Canceled,
ReservedTestProductIDs.Refunded,
ReservedTestProductIDs.Unavailable
}, ItemType.Product);
// Were any products returned?
if (_products == null)
{
// No, abort
return;
}
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
My Helper Method
private IList<Product> _products;
private InAppBillingServiceConnection _serviceConnection;
public void Initalize(IList<Product> _products, InAppBillingServiceConnection _serviceConnection)
{
this._products = _products;
this._serviceConnection = _serviceConnection;
}
// Called when a product is clicked to buy
public bool ProductPurchasing(string id)
{
Product _selectedProduct = null;
try
{
for (int i = 0; i < _products.Count; i++)
{
if (id == _products[i].ProductId)
{
_selectedProduct = _products[i];
break;
}
}
_serviceConnection.BillingHandler.BuyProduct(_selectedProduct);
return true;
}
catch (Exception ex)
{
return false;
}
}

Detect a click on a video link in youtube

I need a method where in when I click a YouTube video in my web view , I need it to perform some action , i.e just get the URL of that video link .
So , how do i get that on click on that video ?
Let's assume video extension is .mp4
In WebViewClient, check for the url with such extension. E.g.
public class myWebClient extends WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains(".mp4"))
{
downloadVideo(url);
}
else
{
view.loadUrl(url);
}
Log.e(TAG, url);
return true;
}
}

BlackBerry stream audio/STOP Stream

)
I'm newbie in programming and have problem.
My code:
choiceFieldANTYFM = new ObjectChoiceField("Wybierz stację(6)", new String[]{"Warszawa [96kb]"});
choiceFieldANTYFM.setChangeListener(this);
btnSelectantyfm = new ButtonField("Słuchaj!", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
btnSelectantyfm.setChangeListener(this);
stopplaying = new ButtonField("STOP", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
stopplaying.setChangeListener(this);
add(choiceFieldANTYFM);
add(btnSelectantyfm);
add(stopplaying);
and other:
public void fieldChanged(Field field, int context) {
if (field == btnSelectantyfm)
{
System.out.println("Selected item: " + Integer.toString(choiceField.getSelectedIndex()));
}if (field == btnSelect)
{
switch (choiceField.getSelectedIndex())
{
case 0:
try {
String url = "http://94.23.220.75:6000;deviceside=false;ConnectionUID=GPMDSEU01";
Player player;
player = javax.microedition.media.Manager.createPlayer(url);
player.start();
}
catch (Exception e) {
Dialog.alert(e.toString());
}
break;
Ok,When I push play it goes music in the application.
When push it again looped back. This is the second problem :)
I want to stop the stream when push stop button and even if it was possible to change the volume keys + and - :)
JDE 5.0 :)
Regards.
Rather than do btnSelectantyfm.setChangeListener(this); which would imply that your Screen is implementing FieldChangeListener declare separate FieldChangeListener objects for each button as follows:
btnSelectantyfm.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//start playing code here
player.start();
}
});
stopplaying.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//stop playing code here
player.stop();
}
});
Now you need to declare the Player object as a member variable so that the play and pause FieldChangeListeners can access it. To stop the Player playing just do player.stop().
For changing the volume when the volume keys are pressed you will need to:
Implement a KeyListener to perform actions when the side volume keys are pressed
Get the VolumeControl from the Player by doing player.getControl("VolumeControl");
Update the VolumeControl with the new desired volume

problem in starting camera?

hie i am using jde 4.5 want to use camera through my app.
i write the code and getting runtime excepetion Pushmodelscreen caaled by non event thread
tell me what the problem in it?
public void start Camera()
{
try {
// Create a player for the Blackberry's camera
Player player= Manager.createPlayer( "capture://video" );
// Set the player to the REALIZED state (see Player javadoc)
player.realize();
// Grab the video control and set it to the current display
_videoControl = (VideoControl)player.getControl( "VideoControl" );
if (_videoControl != null)
{
// Create the video field as a GUI primitive (as opposed to a
// direct video, which can only be used on platforms with
// LCDUI support.)
_videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
_videoControl.setVisible(true);
}
player.start();
if(_videoField!=null)
{
add(_videoField);
}
} catch (Exception e) {
// TODO: handle exception
Dialog.alert(e.getMessage());
}
}
`
thnaks alot
Amit
The code that involved in UI changes should be called from within the UI thread. So most likely some part of your code should be called in a way:
UIApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// do your UI related staff here
// e.g. push a Screen or call Dialog.alert(), etc.
}
});
Also, you may find this info interesting.

Turn on Flash as Light on Blackberry

I am new to BlackBerry application development and trying to make a simple application to turn my flash light on as a torch. I know there are several applications that do this already, but I would like to try do it on my own.
I have installed eclipse and all the necesary add on to get my development environment running. I have also successfully create the stock standard hello world application.
I am however struggling to find out how to do this. I have been reading through the API documentation and started playing with FlashControl, VideoControl and SnapshotControl.
These however don't seem to expose methods to do this.
I know through the video camera I am able to go to options and turn the flash light on and this is exactly what i'm trying to mimic.
The code i have used so far which seems to just set the camera flash to force on is:
Player p = javax.microedition.media.Manager.createPlayer("capture://video");
p.realize();
p.start();
FlashControl flashControl = (FlashControl) p.getControl("javax.microedition.amms.control.camera.FlashControl");
flashControl.setMode(FlashControl.FORCE);
the problem relevant to the flash control has been resolved by me
as per i am using the flash control on my recent application on
camera.
Here is the code which i used :
public Camera(int j)
{
k = j;
try
{
Player player = Manager.createPlayer("capture://video");
player.realize();
_videoControl = (VideoControl) player.getControl("VideoControl");
flashControl = new FlashControl()
{
public void setMode(int mode)
{
// TODO Auto-generated method stub
}
public boolean isFlashReady()
{
// TODO Auto-generated method stub
return false;
}
public int[] getSupportedModes()
{
// TODO Auto-generated method stub
return null;
}
public int getMode()
{
// TODO Auto-generated method stub
return 0;
}
};
flashControl = (FlashControl) player
.getControl("javax.microedition.amms.control.camera.FlashControl");
try {
if (k == 1)
{
flashControl.setMode(FlashControl.AUTO);
Dialog.alert("slect Auto");
}
else if (k == 2)
{
flashControl.setMode(FlashControl.OFF);
Dialog.alert("slect No");
}
}
catch (Exception e)
{
System.out.println(e);
}
if (_videoControl != null)
{
_videoField = (Field) _videoControl.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE,
"net.rim.device.api.ui.Field");
// _videoControl.setDisplaySize(330, 420);
// _videoControl.setDisplayLocation(getContentWidth(),
// getContentHeight());
_videoControl.setVisible(true);
add(_videoField);
capture = new ButtonField("Capture", Field.FIELD_HCENTER);
capture.setChangeListener(this);
add(capture);
player.start();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
this logic has been implemented simultaneously with Pinkesh as my colleage
in the comapny
The FlashControl class, available from OS 5.0 allows you to turn the flash on. Just set a flash control on your player with the FORCE flag:
FlashControl flash = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
if(flash!=null) {
try {
flash.setMode(FlashControl.FORCE);
} catch(IllegalArgumentException iae){}
}
For this to work, you'll probably need to open a player to record video or take a picture. I'm not showing that in my code for the sake of brevity, but here you can read a tutorial. If your app is only about turning on the flash, you'd probably like to have the video field hidden.
Try something like this
LED.setState(LED.STATE_ON); // for LED
Backlight.enable(true); // for Screen
this.setMode(FlashControl.ON); // for flash light.
or else import this package
package lsphone.flash.microfireps;

Resources