Jacky Shin: nsurl * mediafileurl = [nsurl urlwithstring: urlstr];
Nsstring * moviepath = [[nsbundlemainbundle] pathforresource: @ "head" oftype: @ "mov"];
Nsurl * localurl = [[nsurl alloc] initwithstring: moviepath];
Nsurl * localurl1 = [nsurl urlwithstring: moviepath];
Nsurl * localurl2 = [nsurl fileurlwithpath: moviepath];
Nslog (@ "localurl =%@, localurl1 =%@, localurl2 =%@", localurl, localurl1, localurl2 );
Output:
15:26:57. 342 mmp l [4174: 907]
Localurl =/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov, localurl1 =/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov,
Localurl2 = file: // localhost/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov
Lab proof,
1. If the local file is played, the above localurl and localurl1 will cause abnormal playback. The playback page will pop up and then automatically return it as if the playback is complete. However, localurl2 can be used for normal playback. (Test on ipad2 ios6)
2. If you are playing a network file, use the following code in the official example of Apple movieplayer:
Nsurl * themovieurl = [nsurl
Urlwithstring: Self. movieurltextfield. Text];
Is the urlwithstring method used. If it is changed to initwithstring, it can be played normally. If it is changed to fileurlwithpath, it will fail.
The following parts are from the Internet.
Sample Code:
Nsstring * urlstr = @ "http://videourl.com ";
Nsurl * mediafileurl = [nsurl urlwithstring: urlstr];
Mpmoviewplayerviewcontroller * playervc =
[[Mpmovieplayerviewcontroller alloc] initwithcontenturl: mediafileurl] autorelease];
[Self presentmodalviewcontroller: playervc animated: Yes];
[[Playervc movieplayer] Play];
When using a local media file for instantiation, The ios4.x series can be played normally, but when ios5.x is reached,
The following method must be used for instantiation. Otherwise, the media file cannot be played normally. (I personally tested, as I said. Otherwise, the player. view is not visible on the interface)
Nsurl * mediafileurl = [[nsurl alloc] initfileurlwithpath: filepath];
In addition, you can use nsicationicationcenter to obtain various events related to media file playback.
For example:
[[Nsicationcenter center defacenter center] removeobserver: Self
Name: mpmovieplayerplaybackdidfinishnotification
Object: Self. playervc. movieplayer];
[[Nsicationcenter center defacenter center] addobserver: Self
Selector: @ selector (mediafinishedcallback :)
Name: mpmovieplayerplaybackdidfinishnotification
Object: Self. playervc. movieplayer];
For more observer information, see Apple's documentation.