mute/unmute volume in android app - android-audiomanager

i set toggle button for audio..
The mute audio work good but unmute audio doesnt work good..
when i unmute.. it unmute the audio only after restarting the app..
by using this code
AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
amanager.setStreamMute(AudioManager.STREAM_RING, true);
amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
//unmute audio
AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
//
//
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
amanager.setStreamMute(AudioManager.STREAM_RING, false);
amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);

Related

How do I convert the background of Edit Control to transparent in mFC VC++?

Output is show in picture
I am using one CStatic control with variable as "m_background" and ID as IDC_background. In this control, the video has been run on the click of the button. and there is second control Edit Control with variable as "m_edit" and ID as IDC_edit.This Edit Box is placed over static control. I want to show the text written in Edit Control on video while we play video on click of the button with transparent background color of EDit Control.
But the problem is grey/white background has appeared for m_edit control while we play video. I want to show the text on the video with transparent background of the "m_edit" control while we play the video.
BOOL CtestcodeDlg::OnInitDialog()//To set up the video in background and text above the video
{
m_background.ModifyStyle(0, WS_CLIPSIBLINGS);
m_edit.SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE|WS_EX_TRANSPARENT);
return TRUE; // return TRUE unless you set the focus to a control
}
HBRUSH CtestcodeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) //To transparent the background of Edit box
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
HBRUSH m_default=CreateSolidBrush(RGB(0,0, 0));
if(pWnd->GetDlgCtrlID() == IDC_edit)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(TRANSPARENT);
pDC->SetBkMode(TRANSPARENT);
}
return hbr;
}
void CtestcodeDlg::OnBnClickedButton1()////To run the video
{
my_instance = libvlc_new(0, NULL);
my_media_file = libvlc_media_new_location(my_instance,
"rtsp://BigBuckBunny_115k.mov");
my_player = libvlc_media_player_new_from_media(my_media_file);
my_event_manager = libvlc_media_player_event_manager(my_player);
libvlc_media_player_play(my_player);
libvlc_audio_set_track(my_player ,-1);
libvlc_media_player_set_hwnd(my_player, m_background);
Sleep(1000);
_beginthread(test, 0, NULL);
libvlc_audio_set_track(my_player ,-1);
}
Try using SetLayeredWindowAttributes function, with the crKey of your bk color.
Also, i think pDC->SetBkColor(TRANSPARENT); in your code is a mistake, it sets bk color to black. Try to run without this call.

Rotate youtube video with iOS8

I am having a problem with rotate youtube video. I added the following code to my app. And it works for iOS 7. However, it doesn't for iOS8.
In my view controller, I used the following code:
if(IS_OS_6_OR_LATER){
// I use the following notification for iOS 7
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) latername:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];//Notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];//Notification
}
if (IS_OS_8_OR_LATER) {
// I use the following notification for iOS 8
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:UIWindowDidBecomeVisibleNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:UIWindowDidBecomeHiddenNotification object:self.view.window];
}
-(void) youTubeStarted:(NSNotification*) notif {
//Handle event
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = YES;
NSLog(#"start fullscreen");
}
-(void) youTubeFinished:(NSNotification*) notif {
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];//Notification
appDelegate.fullScreenVideoIsPlaying = NO;//Notification
NSLog(#"exit fullscreen");//Notification
}
-(BOOL) shouldAutorotate {
//Handle rotate
NSLog(#"AutoState");
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
//Handle rotate
NSLog(#"AutoState 1");
return UIInterfaceOrientationMaskPortrait;//Notification
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
//Handle rotate
NSLog(#"AutoState 2");
return UIInterfaceOrientationPortrait;//Notification
}
In iOS 7, when video is played in Landscape mode, I press Done button, I see log 'AutoState 1' is shown however I don't see this log when running with iOS 8. Can you help me resolve this on iOS 8? Thank you very much
Instead of limiting the entire app to Portrait and then trying to make the video player allow landscape, you should instead allow landscape all over your app and then limit your invididual view controllers (or the root view controller) to only allow Portrait mode, like this:
In the target settings, allow landscape for your app:
In your view controller(s), add this to limit it to portrait orientation:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

Can't get new iOS 7 camera to scale inside UIPopoverController

My iOS 6 code to show the camera in a UIPopoverController works fine but iOS won't scale the camera view. Please see images below. Any suggestions would be appreciated.
Edit
public class NoRotationUIImagePickerController : UIImagePickerController
{
public override bool ShouldAutorotate ()
{
return false;
}
}
//place imagePicker into a container so that we can control the size of the popover
container = new UIViewController();
container.ContentSizeForViewInPopover = new SizeF(parentViewController.View.Frame.Width, parentViewController.View.Frame.Height);
container.View.AddSubview(_imagePicker.View);
_popOver = new UIPopoverController (container);
//If no camera is available, return false and do nothing.
if (IsCameraHardwareAvailable())
{
_imagePicker.Delegate = new PopUpGalleryPickerDelegate (_popOver, _imageSelected);
_imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
_imagePicker.AllowsEditing = false;
_imagePicker.MediaTypes = new string[] {"public.image"};
RectangleF popRectangle = new RectangleF (new PointF(parentViewController.View.Frame.Width/2, parentViewController.View.Frame.Height/2), new SizeF (1, 1));
_popOver.PresentFromRect(popRectangle, parentViewController.View, 0, true);
_imagePicker.View.Frame = container.View.Frame; //change to frame must come after popover is presented.
}
else
{
cameraAvailable = false;
}
The solution I ended up with was to make the camera full screen instead of using a popover controller.

How to support to play audio file in the background

There is a function in my project to support playing a new audio file even in the background status.I use the MPMoviePlayerController class to play audio files.
But I found it was started in the active status,then it would continue playing the same audio(if the audio file wasn't finished) in the background status;But it won't start a new audio in the background status.
How can I to support playing a new audio in the backgound status?
I found the music player of the iphone can support playing a new audio in the background status,when set runloop or random PlayMode.
The following is my code to prove the appearance in fact:
(void)applicationDidEnterBackground:(UIApplication *)application
{
if (pCotnroller1) {
[pCotnroller1 release];
}
pCotnroller1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://r.yhiker.com:9001/0086/32/05/060009/Data/6/00863205060009006_24Kbps.mp3"]];
pCotnroller1.shouldAutoplay = YES;
[pCotnroller1 play];
//it wasn't played here
}
(void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
if (pCotnroller1) {
switch (pCotnroller1.playbackState) {
case MPMoviePlaybackStateStopped:
NSLog(#"播放地址");
break;
case MPMoviePlaybackStatePaused:
NSLog(#"播放暂停");
break;
case MPMoviePlaybackStateInterrupted:
NSLog(#"播放中断");
break;
case MPMoviePlaybackStateSeekingBackward:
break;
case MPMoviePlaybackStateSeekingForward:
break;
default:
break;
}
if (pCotnroller1.playbackState == MPMoviePlaybackStatePlaying) {
//it will come here,and play autoed here
// [pCotnroller1 play];
}
else
{
}
}
}
I tried some ways which was found in the net,but it didn't work.Some one had used this way to solute his question.I didn’t know why.
the following is my code:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[application beginReceivingRemoteControlEvents];
[self updateUserLocation];
}
- (void)updateUserLocation
{
if (!pCotnroller1) {
// pCotnroller1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://r.yhiker.com:9001/0086/32/05/PP0041/Data/13/00863205PP0041013_24Kbps.mp3"]];
NSString *audioDiskPath = [HelpTools returnSpotAudioDiskPath:#"00863205PP0041013"];
pCotnroller1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:audioDiskPath/*#"/var/mobile/Applications/E7A06CB2-0856-407D-ABA1-2A846B65CD9D/Library/Caches/Data/0086/32/05/PP0041/Data/13/00863205060005016_24Kbps.mp3"*/]];
pCotnroller1.shouldAutoplay = YES;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
[pCotnroller1 play];
NSLog(#"进入后台");
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier taskID = [app beginBackgroundTaskWithExpirationHandler:nil];
if (bgTask != UIBackgroundTaskInvalid) {
[app endBackgroundTask:bgTask];
NSLog(#"允许后台播放");
}
bgTask = taskID;
}
else
{
NSLog(#"飞后台进行播放");
[pCotnroller1 play];
}
}
}
the console print:
2013-03-18 16:20:11.844 Sz[1665:907] [MPAVController] Autoplay: Disabling autoplay for pause
2013-03-18 16:20:11.845 Sz[1665:907] [MPAVController] Autoplay: Disabling autoplay
2013-03-18 16:20:13.489 Sz[1665:907] 文件存在
2013-03-18 16:20:18.017 Sz[1665:907] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-03-18 16:20:18.998 Sz[1665:907] 进入后台
2013-03-18 16:20:21.269 Sz[1665:907] 播放地址
2013-03-18 16:20:26.251 Sz[1665:907] [MPAVController] Autoplay: Enabling autoplay
2013-03-18 16:20:26.307 Sz[1665:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-03-18 16:20:26.309 Sz[1665:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2013-03-18 16:20:26.319 Sz[1665:907] [MPAVController] Autoplay: Enabling autoplay
2013-03-18 16:20:26.338 Sz[1665:907] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0

flash crash when loading a html with webkitgtk

I use webkitgtk to open a html page with some flash files on it. But when I load the page it crashes. My code is given below. What should I do?
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
WebKitWebView *webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
webkit_web_view_set_editable(WEBKIT_WEB_VIEW(webview),TRUE);
GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webview));
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webview, "close-web-view", G_CALLBACK(closewebviewCb), main_window);
gtk_container_add(GTK_CONTAINER(main_window), scrolledWindow);
webkit_web_view_load_uri(webview,URI_PATH);
/******************webkitsetting************************************/
WebKitWebSettings *settings1 = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings1), "enable-plugins", FALSE, NULL);
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(webview), settings1);
g_signal_connect (webview, "notify::load-status", G_CALLBACK (loadStatusCb),NULL);
gtk_widget_grab_focus(GTK_WIDGET(webview));
gtk_widget_show_all(main_window);`

Resources