我正在使用MediaPlayer实例来从Internet位置流式传输音频文件.音频播放器属于单独的活动.用户可以从音频文件列表中进行选择,并参加此活动以播放音频.
现在,用户可能会返回上一个活动(使用列表)并选择另一个音频文件.在这种情况下,我想停止正在播放的任何其他音频并开始播放所选的新音频.
有什么方法我可以知道音频文件是否正在播放而不必保持MediaPlayer对象?
谢谢.
编辑
我确实知道如何知道音频是否正在播放.我们可以通过使用AudioManager的对象并调用isAudioPlaying()来实现.如果正在播放任何音频,则返回true.
现在另一个问题是,如何停止当前播放的音频?我没有为启动音频而创建的MediaPlayer对象的实例(因为用户已经离开了活动一次,并且已经带回活动的新对象,因此是MediaPlayer的新实例)
我正在尝试将我的Resources文件夹中的mp3文件复制到应用程序"Documents"文件夹中的文件夹.在模拟器上这很好用.但是当我在设备上运行它时,复制文件会给我带来这个错误
Operation could not be completed. (Cocoa error 513.)
Run Code Online (Sandbox Code Playgroud)
源和目标路径很好,但我仍然无法复制该文件.有任何想法吗?我在哪里可以找到可可错误代码513的含义?
谢谢.
这是相关的源代码
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
NSString *insPath = [NSString stringWithFormat:@"%@.mp3", fileName];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:insPath];
NSString *destPath = [folderPath stringByAppendingPathComponent:insPath];
NSLog(@"Src: %@, Dest: %@", srcPath, destPath);
NSError *err;
[fileManager moveItemAtPath:srcPath toPath:destPath error:&err];
NSLog(@"Err desc-%@", [err localizedDescription]);
NSLog(@"Err reason-%@", [err localizedFailureReason]);
Run Code Online (Sandbox Code Playgroud)
在调用moveItemAtPath之前,我还创建了目录"Files",它返回YES.
这是日志结果
Src: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/MyApp.app/MyFile.mp3, Dest: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/Documents/Files/MyFile.mp3
Err desc-Operation could not be completed. (Cocoa error …Run Code Online (Sandbox Code Playgroud) 我正在为我的UINavigationBar添加自定义背景.只要手机处于纵向模式,它就能正常工作.一旦我切换到横向模式,一半的条形显示为蓝色(默认的导航栏颜色),其中一半有我的图像
如何在横向模式下拉伸图像并在纵向模式下再次缩小图像?
谢谢
解决方案如果
有人正在寻找如何将图像添加到导航栏的答案 - 就在这里
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 44.0)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"navbar_landscape" ofType:@"png"]]];
[navigationController.navigationBar addSubview:imgView];
[imgView release];
Run Code Online (Sandbox Code Playgroud) 有没有人有幸运行两个iPhone模拟器实例来测试两者之间的网络代码?
如何使用AppleScript查找Mac上安装的OSX版本?我想以编程方式安装应用程序,并根据版本运行不同的pkg文件.
谢谢
我正在使用Three20库中的TTPhotoViewController子类来显示来自Web位置的图像.图像加载正常,但导航栏和工具栏显示默认色调.我正在使用带有自定义色调的导航栏(在MainWindow.xib中设置)
我试过这些东西让它显示黑色半透明条,但这些似乎都没有效果.
有人可以告诉我为什么会发生这种情况以及如何解决这个问题?谢谢.
当用户的焦点到达ImageButton时,是否可以指定不同的图像?我想在LinearLayout上显示图像按钮,并在用户的焦点出现在按钮上或用户按下按钮时更改图像.
谢谢.
当出现异常时,如何从不同的线程切换回主线程.当在子线程上引发异常时,我希望将通知发送到主线程并从主线程执行方法.我怎样才能做到这一点?
谢谢.
附加信息
我从我的main方法调用一个方法,并在经过一些计算和更改之后在那里开始一个新线程
Thread thread = new Thread() {
@Override
public void run() {
.....
}
}
thread.start();
Run Code Online (Sandbox Code Playgroud) 我正在开发一个音频流媒体,并宣布一个中断监听器,以便在发生中断时保存歌曲的状态 - 如来电或短信.
这是相关的代码
在我的AppDelegate中,我有这个
AudioSessionInitialize (NULL, NULL, interruptionListenerCallback, self);
AudioSessionSetActive(YES);
Run Code Online (Sandbox Code Playgroud)
这就是中断监听器的样子
void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
// This callback, being outside the implementation block, needs a reference
//to the AudioPlayer object
MyPlayer *player = (MyPlayer *)inUserData;
if (interruptionState == kAudioSessionBeginInterruption) {
if ([player audioStreamer]) {
// if currently playing, pause
[player pausePlayback];
player.interruptedOnPlayback = YES;
}
} else if ((interruptionState == kAudioSessionEndInterruption) && player.interruptedOnPlayback) {
// if the interruption was removed, and the app had been playing, …Run Code Online (Sandbox Code Playgroud) 是否有可能从应用程序中找到我的iphone附近的蓝牙设备?我可以使用GameKit框架来完成它,但这有限制,两个设备必须安装并运行我的应用程序.
有没有办法使用蓝牙检测附近的iPhone设备,即使他们没有运行相同的应用程序?
谢谢.